<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目报价方案</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
			<div tabid="tabA" title="基本信息" lselected="true">
	            <form id="formSet1">
	                <div class="fieldset1 tabel_col clearFix">
	                    <div class="fieldBox col_33">
		                    <div class="label">方案名称</div>
		                    <div class="field">
		                   <input name="prpsCfgNm" id="prpsCfgNm" type="text" class="ui-textbox"   readonly="readonly" value="${quatPrps.prpsCfgNm}" >
		                   <input name="prpsCfgId" id="prpsCfgId" type="hidden" class="ui-textbox"   value="${quatPrps.id}" >
		                   <input name="isDef" id="isDef" type="hidden" class="ui-textbox"   value="${quatPrps.isSysDef}" >
		            	   <input name="prpsId" id="prpsId" type="hidden" class="ui-textbox"   value="${id}" >
		            	   <input name="isAllowChg" id="isAllowChg" type="hidden" class="ui-textbox"   value="${quatPrps.isAllowChg}" >
		            	   <input name="isAllowAdd" id="isAllowAdd" type="hidden" class="ui-textbox"   value="${quatPrps.isAllowAdd}" >
		            	   <input name="prpsTypCd" id="prpsTypCd" type="hidden" class="ui-textbox"   value="${quatPrps.prpsTypCd}" >

		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁物件总价值</div>
		                    <div class="field">
		                        <input name="totLsItmAmt" id="totLsItmAmt"  readonly="readonly" type="text" class="ui-textbox"  onblur="changeBaseTotLsltmAmt(0)" value="${totalPrdAmt}" validate="{required:true}">
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">合同总额（元）</div>
		                    <div class="field">
                                <c:if test="${prjTypCd =='CDDYWUL' or prjTypCd =='ESCJYD' or prjTypCd =='OWNJYD'}" >
                                    <input name="contAmt" id="contAmt" type="text"  readonly="readonly" class="ui-textbox"  value="${cntAmt}"  onblur="changeBaseContAmt(0)" validate="{required:true}">
                                </c:if>
                                <c:if test="${prjTypCd !='CDDYWUL' and prjTypCd !='ESCJYD' and prjTypCd !='OWNJYD'}" >
                                    <input name="contAmt" id="contAmt" type="text"  readonly="readonly" class="ui-textbox"  value="${totalPrdAmt}"  onblur="changeBaseContAmt(0)" validate="{required:true}">
                                </c:if>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">利率上浮比例</div>
		                    <div class="field">
		                        <input name="intRateRsPct" id="intRateRsPct"  onblur="changeAnnIntRatePct()" type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div>
		                  <div class="fieldBox col_33"  id="splitPct" style="display: none">
		                    <div class="label">拆分比例</div>
		                    <div class="field">
		                    <select name="quatSplitPct" id="quatSplitPct" data-value=""  validate="{required:true}"  style="display: none">
		                        	<option value="" checked >请选择</option>
									<c:forEach items="${prjQuatSplitPctList }" var="kv">
									    <option value="${kv.key }" >${kv.value }</option>
									</c:forEach>
							</select>
		                    </div>
		                </div>

						<div class="fieldBox col_33"  id="rentAllowanceServiceDiv" style="display: none">
							<div class="label">捆绑租金补助服务</div>
							<div class="field">
								<select name="rentAllowanceService" id="rentAllowanceService" data-value=""  >
									<option value="2" checked >请选择</option>
									<option value="0"  >否</option>
									<option value="1"  >是</option>
								</select>
							</div>
						</div>

		                   <div class="fieldBox col_33"  id="prjPreRntPctDiv" style="display: none">
		                    <div class="label">前期租金比率</div>
		                    <div class="field">
		                    <select name="preRntPct" id="preRntPct" data-value=""  >
		                        	<option value="" checked >请选择</option>
									<c:forEach items="${prjPreRntPctList }" var="kv">
									    <option value="${kv.key }" >${kv.value }</option>
									</c:forEach>
							</select>
		                    </div>
		                </div>
		                <div class="fieldBox col_33"  id="splitPctTxt" style="display: none">
		                    <div class="label">打分比例</div>
		                    <div class="field" >
		                    	<input name="splitPctValue" id="splitPctValue"  type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div>

		                 <div class="fieldBox col_100">
		                    <div class="label">租赁期数</div>
		                    <div class="field">
		                        <input name="lsPd" id="lsPd" type="text" class="ui-textbox"  value="${quatPrps.lsPd}"  onchange="searchAnnIntRatePct()" validate="{required:true,number:true}">
		                         <select name="lsPdUntCd" id="lsPdUntCd" data-value=" " onchange="searchAnnIntRatePct()">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${lsPdUntCdList }" var="kv">
									    <option value="${kv.key }"
									    <c:if test="${quatPrps.lsPdUntCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
								 </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁周期</div>
		                    <div class="field">
		                      <span id="rentPeriod"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁年利率%</div>
		                    <div class="field">
		                      <input name="annIntRatePct" id="annIntRatePct" type="text" class="ui-textbox"  value="${annIntRatePct}">
		                    </div>
		                </div>

						<div class="fieldBox col_33">
							<div class="label">计算方式</div>
							<div class="field">
								<select name="lsCalWayCd" id="lsCalWayCd" data-value=" ">
									<c:forEach items="${lsCalWayCdList }" var="kv">
										<option value="${kv.key }" >${kv.value }</option>
									</c:forEach>
								</select>
							</div>
						</div>

		                  <div class="fieldBox col_33">
		                    <div class="label">实际融资租赁价值</div>
		                    <div class="field">
		                       <input name="actLsAmt" id="actLsAmt" type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">支付方式</div>
		                    <div class="field">
		                        <select name="payWayCd" id="payWayCd" data-value=" "   onchange="setSplitDefValue();" validate="{required:true}">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${payWayCdList }" var="kv">
									    <option value="${kv.key }"
									    <c:if test="${quatPrps.payWayCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
						<div class="fieldBox col_33" id = "speLsPdDiv" style = "display: none">
							<div class="label">不还款期数</div>
		                    <div class="field">
								<input name="speLsPd" id="speLsPd"  type="text" class="ui-textbox"  value="">
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">每期预估租金</div>
		                    <div class="field">
		                      <input name="eachEstRntAmt" id="eachEstRntAmt"  type="text" class="ui-textbox"  value="" readonly="readonly">
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">租赁系数</div>
		                    <div class="field">
		                        <input name="lsCoe" id="lsCoe" type="text" class="ui-textbox"  value="${quatPrps.lsCoe}" validate="{number:true}"  readonly="readonly">
		                    </div>
		                </div>
		               <div class="fieldBox col_33">
		                    <div class="label">租赁年利率计算方式</div>
		                    <div class="field">
		                        <select name="intRateWayCd" id="intRateWayCd" data-value=" ">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${intRateWayCdList }" var="kv">
									    <option value="${kv.key }" >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">客户保证金处理方式</div>
		                    <div class="field">
		                        <select name="dpstHdlWayCd" id="dpstHdlWayCd" data-value=" ">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${dpstHdlWayCdList }" var="kv">
									    <option value="${kv.key }"
								        <c:if test="${quatPrps.dpstHdlWayCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">租赁期满处理方式</div>
		                    <div class="field">
		                        <select name="expHdlWayCd" id="expHdlWayCd" data-value=" ">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${expHdlWayCdList }" var="kv">
									    <option value="${kv.key }"
				                         <c:if test="${quatPrps.expHdlWayCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>

		                  <div class="fieldBox col_33"  id="isBpDiv">
		                    <div class="label">是否包牌价</div>
		                    <div class="field">
		                        <select name="isBp" id="isBp" data-value=" " >
									<c:forEach items="${isBpList}" var="kv">
									    <option value="${kv.key }">${kv.value }</option>
									</c:forEach>
								</select>
								  <span class="requiredSymbol"  id="isBpReq">*</span>
		                    </div>
		                </div>

		                <%--   <div class="fieldBox col_33" id="businessInsCdDiv">
		                    <div class="label">商业险金额</div>
		                    <div class="field">
		                        <select name="businessInsCd" id="businessInsCd" data-value=" ">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${businessInsCdList }" var="kv">
									    <option value="${kv.key }">${kv.value }</option>
									</c:forEach>
								</select>
								  <span class="requiredSymbol"  id="businessInsCdReq">*</span>
		                    </div>
		                </div> --%>
		             <%--     <div class="fieldBox col_33">
		                    <div class="label">不还款处理方式</div>
		                    <div class="field">
		                        <select name="noPayWayCd" id="noPayWayCd" data-value=" ">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${noPayWayCdList }" var="kv">
									    <option value="${kv.key }">${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div> --%>
		                  <div class="fieldBox col_33">
		                    <div class="label">首付款</div>
		                    <div class="field">
		                    <span id="firstPayAmt"></span>
		                    </div>
		                </div>
					    <div class="fieldBox col_33">
		                    <div class="label">实际收益率(IRR)</div>
		                    <div class="field">
		                      <input name="irrPct" id="irrPct"  type="text" class="ui-textbox"  value=""  readonly="readonly" validate="{number:true}">
		                    </div>
		                </div>
						<div class="fieldBox col_33" hidden="hidden">
							<div class="label">拿去用额度</div>
							<div class="field">
								<input name="smallLoanAmt" id="smallLoanAmt"  type="text" class="ui-textbox"  value=""  readonly="readonly">
							</div>
						</div>
						<div class="fieldBox col_33" hidden>
							<div class="label">是否申请专享额度</div>
							<div class="field">
								<select name="isLowDownPayment" id="isLowDownPayment" data-value=" " >
									<option value="" selected>-请选择-</option>
									<option value="0">否</option>
									<option value="1">是</option>
								</select>
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<c:if test="${isDealer}">
							<div class="fieldBox col_33"  id="specialBusinessDiv">
								<div class="label">特殊业务类型</div>
								<div class="field">
									<select name="specialBusinessType" id="specialBusinessType">
										<option value=" " selected="selected">无</option>
										<c:forEach items="${specialBusiness}" var="kv">
											<option value="${kv.key}" >${kv.value}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="fieldBox col_33" id="chlDpstPwayCdDiv" style="display: none">
								<div class="label">渠道保证金退还方式</div>
								<div class="field">
									<select name="chlDpstPwayCd" id="chlDpstPwayCd" data-value=" ">
										<option value=" " checked >请选择</option>
										<c:forEach items="${chlDpstPwayCdList}" var="kv">
											<option value="${kv.key }">${kv.value }</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="fieldBox col_33" id="chlDpstRtnPdDiv" style="display: none">
								<div class="label">退还期次</div>
								<div class="field">
									<input name="rtnPdStart" id="rtnPdStart" type="text" class="ui-textbox"  value="1" validate="{number:true}"  readonly="readonly"> -
									<input name="rtnPdEnd" id="rtnPdEnd" type="text" class="ui-textbox"  value="6" validate="{number:true}"  readonly="readonly">
								</div>
							</div>
						</c:if>
						<div class="fieldBox col_33"  id="isLowBizDiv">
							<div class="label">是否低息</div>
							<div class="field">
								<select name="isLowBiz" id="isLowBiz">
									<option value="0" selected="selected">否</option>
									<option value="1">是</option>
								</select>
							</div>
						</div>

		              <div class="fieldBox col_33"  id="mfrDiscountRateDiv" style="display: none">
		                    <div class="label">厂商贴息利率</div>
		                    <div class="field">
		                      <input name="mfrDiscountRate" id="mfrDiscountRate"  type="text" class="ui-textbox"  value="${mfrDiscountRate}"    validate="{number:true}">
		                    </div>
		                </div>
		                 <div class="fieldBox col_33"  id="policyTypCdDiv" style="display: none">
		                    <div class="label">方案政策类型</div>
		                    <div class="field">
		                    <select name="policyTypCd" id="policyTypCd" data-value=""  >
		                        	<option value="" checked >请选择</option>
									<c:forEach items="${policyTypCdList}" var="kv">
									    <option value="${kv.key }">${kv.value }</option>
									</c:forEach>
							</select>
		                    </div>
		                </div>
		                <div class="fieldBox col_33"  id="irrPct2Div" style="display: none">
		                    <div class="label">实际收益率(IRR2)</div>
		                    <div class="field">
		                      <input name="irrPct2" id="irrPct2"  type="text" class="ui-textbox"  value=""   readonly="readonly" validate="{number:true}">
		                    </div>
		                </div>
						<div class="fieldBox col_33">
							<div class="label">对客IRR</div>
							<div class="field">
								<input name="cstIrr" id="cstIrr"  type="text" class="ui-textbox"  value="${cstIrr}" readonly="readonly" validate="{number:true}">
							</div>
						</div>
						<div class="fieldBox col_33"  id="oneCityOnePolicyTypeCdDiv" style="display: none">
							<div class="label">一城一策标记</div>
							<div class="field">
								<select name="oneCityOnePolicyTypeCd" id="oneCityOnePolicyTypeCd" data-value=""  >
									<option value=" " checked >请选择</option>
									<c:forEach items="${oneCityOnePolicyTypeCdList}" var="kv">
										<option value="${kv.key }">${kv.value }</option>
									</c:forEach>
								</select>
							</div>
						</div>
                        <div class="fieldBox col_33"  id="tenThouCoefDiv" style="display: none">
                            <div class="label">万元系数</div>
                            <div class="field">
                                <input name="tenThouCoef" id="tenThouCoef"  type="text" class="ui-textbox"  value="" >
                            </div>
                        </div>
                        <div class="fieldBox col_33" >
                            <div class="label">新旧报价方案选择</div>
                            <div class="field">
                                <select name="noPayWayCd" id="noPayWayCd" data-value="old"  >
									<option value="new">新报价</option>
									<option value="old">老报价</option>
								</select>
                            </div>
                        </div>
		                <div class="fieldBox col_100"  id="msgDiv" style="display: none">
							<div class="label">注意事项：</div>
									<div class="field">
									<span style="color: red">1：0%首付（含保证金），IRR 15.5%；2：5%首付(含保证金)，IRR 15%；3：10%首付（含保证金），IRR14.7%</span>
									 </div>
							</div>
                      <%--  <div class="fieldBox col_100"  id="insMsgDiv" style="display: none">
                            <div class="label">支持的资管机构：</div>
                            <div class="field">
                                <span style="color: red" id="checkInfo"></span>
                            </div>
                        </div>--%>
				        <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div class="sqPanel_head inL">
				                    <div class="btnsBox inLC">
				                        <span id="addBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_3"></i> -->添加</span>
				                        <span id="delBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_7"></i> -->删除</span>
				                    </div>
				                </div>
				                 <br/>
				                  <br/>
				                <div id="detailGrid">
				                    <div id="ligergrid_fee" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				          <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div id="feePayGrid">
				                    <div id="ligergrid_calculate" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				         <div class="fieldBox col_33">
		                    <div class="label">合计租金：</div>
		                    <div class="field">
		                    <span id="totalRntAmt"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">合计本金：</div>
		                    <div class="field">
		                    <span id="totalPrinAmt"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">合计利息：</div>
		                    <div class="field">
		                    <span id="totalIntAmt"></span>
		                    </div>
		                </div>
	                </div>
	                <div class="btnsBox">
	                   <span id="calculateBtn1"  class="sq-button sq-button-round"><!-- <i class="sqBtnIco_10"></i> -->测算</span>
	                    <span id="recovery"  onclick="recoveryData()" class="sq-button sq-button-round" style="display: none;"><!-- <i class="sqBtnIco_10"></i> -->恢复</span>
		                <span id="saveBtn1" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_10"></i> -->保存</span>
		             <%--    <input name="prpsCfgId" id="prpsCfgId" type="hidden" value="${quatPrps.id }"> --%>
		            </div>
	            </form>
				<div id="res_div" style="display:none">
					<div class="btnsBox">
						<span id="isAllowNonIns" class="sq-button sq-button-round"></span>
						<span id="applySpecial" class="sq-button sq-button-round">申请特批</span>
					</div>
					<div id="grid_heguijigou" class="sq-grid"></div>
					<div id="defaultTip" class="fieldBox">
						<br>
						<p>点击【确认】筛选页面信息才会保存哦</p>
						<p>存在合规机构但是需要做非资管业务的情况，请点击【申请特批】按钮发起特批流程进行审批</p>
						<br>
					</div>
					<div id="defaultText" class="fieldBox" style="display: none">
						<p>暂无符合情况的资管机构，点击确认提交非资管业务</p>
						<br>
					</div>
					<div id="grid_heguijigouUn" class="sq-grid"></div>
					<div class="btnsBox TC">
						<span id="confirmBtn" class="sq-button sq-button-round">确认</span>
					</div>
				</div>
		</div>
	</div>
</div>
<form id="capFundConfirm_form" style="display: none;">
	<div class="fieldset1 clearFix">
		<div class="fieldBox">
			<p>您尚未选择任一合规资金方，请选择。</p>
			<p>如因特殊原因不选择任一资方，请填写原因提交资管业务特批申请。</p>
			<br>
		</div>
		<div class="fieldBox">
			<div class="label">申请原因：</div>
			<div class="field">
                    <textarea name="docketRem" id="docketRem" class="ui-textarea l-textarea"
							  rows="7" cols="60" style="width: 300px;" validate="{required:false,maxlength:200}"></textarea>
			</div>
		</div>
	</div>
</form>
<form id="confirm_form" style="display: none;">
	<div class="fieldset1 clearFix">
		<div class="fieldBox">
			<p>按此修改机构信息将会：</p>
			<p>1.删除现有报价及支付表</p>
			<p>2.删除银行卡信息和资方开户信息</p>
			<p>确定修改吗？</p>
			<br>
		</div>
	</div>
</form>
<script type="text/javascript">
var arrFoundCode = [];
<c:forEach items="${friBaseList}" var= "module">
var item  = {"fundRasInsId":"${module.id}","fundRasInsNmShow":"${module.fundRasInsNmShow}"};
arrFoundCode.push(item);
</c:forEach>

var feeGrid;//费用明细信息
var quatId = '${quatId}';
var prjId = '${prjId}';
// 根据这个标识判断修改和查看
var detailFlag = '${detailFlag}';
var isSupportLowRateForDealers = '${isSupportLowRateForDealers}';
var isDealer = '${isDealer}';
var calculateGrid;
var annIntRatePct = 0;
var isModify = false;
var prpsCfgId = '${prpsCfgId}';
var quatPrps='${quatPrps}';
var quatPrpsJson  ='${quatPrpsJson}';
var totalRsrvPcStr = '${totalRsrvPcStr}';
var prpsTypCd = '${prpsTypCd}';
var isFlow = '${isFlow}';
var defSplitPct = '${defSplitPct}';
var buOrgCd = '${buOrgCd}';
var prjTypCd = '${prjTypCd}';
var ycPdList = '${ycPdList}';
var prdNum = '${prdNum}'
var isShowBp = '${isShowBp}';
var insCode = '${insCode}';
var isInsBiz = '${isInsBiz}';
var isSplMfr = '${isSplMfr}';
var calId = '${calId}';
var preInsId = '${calId}';
//产品数量
var prdList = '${prdList}';
// 报价方案的名字
var prpsCfgNm = '${quatPrps.prpsCfgNm}';
//是否低息
var isLowBiz = '${isLowBiz}';
//是否显示低息 0-不显示,1-显示
var isLowBizFlag = '${isLowBizFlag}';
var insRouteInfo = '${insRouteInfo}';
var dsCd = '${dsCd}';
//费用类型
var feeTypCdListJSON = [];
<c:if test="${not empty feeTypCdListJSON}"> feeTypCdListJSON = ${feeTypCdListJSON}; </c:if>
//费用计算基数
var calBaseCdListJSON = [];
<c:if test="${not empty calBaseCdListJSON}"> calBaseCdListJSON = ${calBaseCdListJSON}; </c:if>
//费用计入方式
var cntWayCdListJSON = [];
<c:if test="${not empty cntWayCdListJSON}"> cntWayCdListJSON = ${cntWayCdListJSON}; </c:if>
//是否
var yesOrNoCdListJSON = [];
<c:if test="${not empty yesOrNoCdListJSON}"> yesOrNoCdListJSON = ${yesOrNoCdListJSON}; </c:if>
var scaleNumMap = '${scaleNumMap}';
var feeScale = 0;
var annIntScale = 0;
var floatScale = 0;
var ligerGrid_heguijigou;
var ligerGrid_heguijigouUn;
var isAllowNonIns = CommonConstant.C_YN_Y;
var searchAnnIntRatePctMark = CommonConstant.C_YN_N;
var compensatoryType = '${compensatoryType}' ;
if(scaleNumMap.length>0){
	scaleNumMap = JSON.parse(scaleNumMap);
for(var key in scaleNumMap) {
	if(key==ProjectConstant.CODE_ANNINT_RATE_NUM_CD){
	annIntScale = parseInt(scaleNumMap[key]);
	}
	if(key==ProjectConstant.CODE_FLOAT_RATE_NUM_CD){
	floatScale = parseInt(scaleNumMap[key]);
	}
	if(key==ProjectConstant.CODE_FEE_DECI_NUM_CD){
	feeScale = parseInt(scaleNumMap[key]);
	}
}
} else{
	feeScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
	annIntScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
	floatScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
}
$(function(){
	if(StringUtils.isNotEmpty(insRouteInfo)){
		UIUtils.alertSuccessHold1(insRouteInfo);
	}
	$('#formSet1').ligerForm({
        validate : true
	});
	var editFlag = true;
 	if(detailFlag=="true"){
		editFlag = false;
		$("#calculateBtn1").hide();
		$("#saveBtn1").hide();
		$("#addBtn").hide();
		$("#delBtn").hide();
		$("#recovery").hide();
	}
    //默认不显示是否低息字段(新增，查看都有)
    $("#isLowBizDiv").hide();
 	/*
    //重卡传统业务，重卡城配业务
    if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK
        && (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW || prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)){
        //资方为浦发，苏宁，三湘 显示是否低息
        if(insCode == ProjectConstant.PRJ_INS_CODE_PSD
            || insCode == ProjectConstant.PRJ_INS_CODE_SN
            || insCode == ProjectConstant.PRJ_INS_CODE_SNS
            || insCode == ProjectConstant.PRJ_INS_CODE_SX
			|| insCode == ProjectConstant.PRJ_INS_CODE_CC
			|| insCode == ProjectConstant.PRJ_INS_CODE_ZGC
			|| insCode == ProjectConstant.PRJ_INS_CODE_HRBANK){
            $("#isLowBizDiv").show();
            //查看报价方案不允许修改是否低息字段
            if(isLowBiz != ""){
                if (isLowBiz ==0 || isLowBiz ==1) {
                    var selectid= $("#isLowBiz").ligerGetComboBoxManager();
                    selectid.setValue(isLowBiz);
                }
            }
            //detailFlag为true表示查看报价方案，不允许编辑
            if(detailFlag=="true"){
                liger.get("isLowBiz").setDisabled(true);
            }
			//如果经销商不支持低息
			if(isSupportLowRateForDealers=="false"){
				liger.get("isLowBiz").setDisabled(true);
			}
			//如果收款方类型 不是经销商
			if(isDealer=="false"){
				liger.get("isLowBiz").setDisabled(true);
			}
        }
    }
    */
 	if (CommonConstant.C_YN_Y == isLowBizFlag) {
		$("#isLowBizDiv").show();
		//查看报价方案不允许修改是否低息字段
		if(isLowBiz != ""){
			if (isLowBiz ==0 || isLowBiz ==1) {
				var selectid= $("#isLowBiz").ligerGetComboBoxManager();
				selectid.setValue(isLowBiz);
			}
		}
		//detailFlag为true表示查看报价方案，不允许编辑
		if(detailFlag=="true"){
			liger.get("isLowBiz").setDisabled(true);
		}
		//如果经销商不支持低息
		if(isSupportLowRateForDealers=="false"){
			liger.get("isLowBiz").setDisabled(true);
		}
		//如果收款方类型 不是经销商
		if(isDealer=="false"){
			liger.get("isLowBiz").setDisabled(true);
		}
	}
    if(compensatoryType != '2'){
        $("#chlDpstPwayCdDiv").hide();
        $("#chlDpstRtnPdDiv").hide();
    }
	var prpsId=$("#prpsId").val();
	if(!prpsId){
		 var baseForm1 = liger.get("formSet1");
		 baseForm1.setData({
			 intRateWayCd:ProjectConstant.CODE_DEF_INT_RATE_WAY_CD
     	 });
	}
	if(prpsTypCd==ProjectConstant.CODE_PAY_QUAT_PRPS_OFFICIAL){
		$("#splitPctTxt").show();
	}
   if(prpsTypCd==ProjectConstant.CODE_PAY_QUAT_PRPS_QUOTE){
		$("#splitPct").show();
	}
/*   if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK){
		$("#msgDiv").show();
	}  */
	var isBpVal = liger.get('isBp');
	if(prjTypCd == ProjectConstant.PRJ_TYP_CD_CDDYWYQ){
		isBpVal.setValue(0);
		liger.get("isBp").setDisabled(true);
	}else{
		isBpVal.setValue('${isBp}');
	}
	if(prjTypCd==ProjectConstant.PRJ_TYP_CD_CDDYWYQ){
		$("#irrPct").val(20);
		$("#annIntRatePct").attr("readonly","readonly");
		var annIntRatePctYq =  $("#annIntRatePct").val();
		if(annIntRatePctYq == "" || annIntRatePctYq == "0"){
			$("#annIntRatePct").val(20);
		}
	}
	if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK){
		 $("#preRntPct").attr("validate", "");
        if((prjTypCd==ProjectConstant.PRJ_TYP_CD_CPYW && isSplMfr == '1')||(prjTypCd==ProjectConstant.PRJ_TYP_CD_CTYW && isSplMfr == '1')){
			$("#mfrDiscountRateDiv").show();
			$("#irrPct2Div").show();
			$("#policyTypCdDiv").show();
		}else{
			$("#irrPct").attr("readonly","readonly");
		}
		$("#isBpDiv").show();
		var ligerForm = liger.get("formSet1");
	    //var isBp = liger.get('isBp');
			//isBp.setValue("0");
		//isBp.setValue('${isBp}');
       /* if(isShowBp==0&&!insCode){
            liger.get("isBp").setDisabled(true);
        }*/
		/* if(isShowBp==1){
		     ligerForm.setFieldValidate("isBp", {
                 required: true,
                 select: true
             });
			//$("#isBp").attr("validate", "{required:true}");
			$("#isBpReq").show();
			$("#isBpDiv").show();
		}else{
		     ligerForm.setFieldValidate("isBp", {
                 required: true,
                 select: false
             });
			//$("#isBp").attr("validate", "");
			$("#isBpDiv").hide();
			$("#isBpReq").hide();
		} */
	}
	if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK && (prjTypCd==ProjectConstant.PRJ_TYP_CD_CPYW||prjTypCd==ProjectConstant.PRJ_TYP_CD_CTYW)){
		$("#oneCityOnePolicyTypeCdDiv").show();
	}
	/**
     * 捆绑租金补助服务
     * 重卡事业部(传统、城配)
     */
    if(buOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK && (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW || prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)) {
		console.log(prdList)
		console.log(typeof prdList )
		console.log(JSON.parse(prdList))
		var prdListArray = JSON.parse(prdList);


        if (insCode == '' || insCode == null) {
            // 我司且报价方案名称为重卡灵活报价方案，显示捆绑租金补助服务下拉框
            if (prpsCfgNm == '重卡灵活报价方案') {
                // 显示
                $("#rentAllowanceServiceDiv").show();

                /*
                 * 判断下项目车型校验，该项目下全是挂车，下拉选项置灰不可操作，初始状态是否
                 */
				// 用于标记挂车的数量
				var j = 0;
				for(var i = 0;i < prdListArray.length;i ++) {
					var prdTypCd = prdListArray[i].prdTypCd;
					if (prdTypCd == ProjectConstant.PRD_TYP_CD_9) {
						j ++;
					}
				}
				console.log("挂车数量:"+ j);
				// 如果j的值等于产品的数量，说明该项目下全是挂车
				// 下拉框置灰不可操作，初始状态是否
				if (j == prdListArray.length) {
					var selectid= $("#rentAllowanceService").ligerGetComboBoxManager();
					selectid.setValue(0);
					selectid.setText('否');
					//$("#rentAllowanceService").attr("disabled","disabled");
					liger.get("rentAllowanceService").setDisabled(true);
				}
            }
        } else {
            //资管项目 显示捆绑租金补助服务下拉框
            $("#rentAllowanceServiceDiv").show();
        }
    }

	if(isShowBp==CommonConstant.C_YN_N){
		var ligerForm = liger.get("formSet1");
		ligerForm.setFieldValidate("isBp", {
			required: false,
			select: false
		});
		$("#isBpDiv").hide();
	}

	if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_YC||buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK){
		var payWayCd = $("#payWayCd").val();
		if(payWayCd==ProjectConstant.CODE_MULTI__STEP_INTER){
			  $("#preRntPct").attr("validate", "{required:true}");
			$("#prjPreRntPctDiv").show();
		}else{
			 $("#preRntPct").attr("validate", "");
			$("#prjPreRntPctDiv").hide();
		}
	}
    if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZC&&insCode==ProjectConstant.PRJ_INS_CODE_PF){
        $("#tenThouCoefDiv").show();
    }
	if(prpsId){
		var prjQuatPrps = '${prjQuatPrps}';
	 	prjQuatPrps = JSON.parse(prjQuatPrps);
	 	if(compensatoryType == '2'){
            $("#chlDpstPwayCdDiv").show();
            $("#chlDpstRtnPdDiv").show();
            $("#chlDpstPwayCd").ligerGetComboBoxManager().setValue(prjQuatPrps.chlDpstPwayCd) ;
            $("#rtnPdStart").ligerGetComboBoxManager().setValue(prjQuatPrps.rtnPdStart) ;
            $("#rtnPdEnd").ligerGetComboBoxManager().setValue(prjQuatPrps.rtnPdEnd) ;
        }
        if(prjQuatPrps.smallLoanAmt && prjQuatPrps.smallLoanAmt > 0){
            $("#smallLoanAmt").parent().parent().parent().show();
            $("#isLowDownPayment_txt").show().parent().parent().parent().parent().show();
            $("#smallLoanAmt").val(prjQuatPrps.smallLoanAmt);
            var isLowDownPaymentId= $("#isLowDownPayment").ligerGetComboBoxManager();
            isLowDownPaymentId.setValue(prjQuatPrps.isLowDownPayment);
        }
        if(isDealer == 'true'){
			//特殊业务下拉框回显
			console.log('specialBusinessType' + prjQuatPrps.specialBusinessType);
			var specialBusinessType= $("#specialBusinessType").ligerGetComboBoxManager();
			if(prjQuatPrps.specialBusinessType != null){
				specialBusinessType.setValue(prjQuatPrps.specialBusinessType);
			}else{
				specialBusinessType.setValue(" ");
			}
			if(detailFlag=="true"){
				liger.get("specialBusinessType").setDisabled(true);
			}
			liger.get("isLowBiz").setDisabled(true);
		}
        //初始化修改数据
	 	 var form = liger.get("formSet1");
	 		form.setData({
	 			prpsCfgNm:prjQuatPrps.prpsCfgNm,
	 			prpsCfgId:prjQuatPrps.prpsCfgId,
	 			isSysDef:prjQuatPrps.isSysDef,
	 			prpsId:prjQuatPrps.prpsId,
	 			totLsItmAmt:prjQuatPrps.totLsItmAmt,
	 			contAmt:prjQuatPrps.contAmt,
	 			intRateRsPct:parseFloat(prjQuatPrps.intRateRsPct==null?0:prjQuatPrps.intRateRsPct),
	 			lsPd:prjQuatPrps.lsPd,
	 			lsPdUntCd:prjQuatPrps.lsPdUntCd,
	 			annIntRatePct:parseFloat(prjQuatPrps.annIntRatePct==null?0:prjQuatPrps.annIntRatePct),
	 			payWayCd:prjQuatPrps.payWayCd,
	 			actLsAmt:prjQuatPrps.actLsAmt,
	 			eachEstRntAmt:prjQuatPrps.eachEstRntAmt,
				speLsPd:prjQuatPrps.speLsPd,
	 			lsCalWayCd:prjQuatPrps.lsCalWayCd,
	 			lsCoe:prjQuatPrps.lsCoe,
	 			intRateWayCd:prjQuatPrps.intRateWayCd,
	 			dpstHdlWayCd:prjQuatPrps.dpstHdlWayCd,
	 			expHdlWayCd:prjQuatPrps.expHdlWayCd,
	 			noPayWayCd:prjQuatPrps.noPayWayCd,
	 			quatSplitPct:prjQuatPrps.quatSplitPct,
	 			irrPct:prjQuatPrps.irrPct,
	 			irrPct2:prjQuatPrps.irrPct2,
	 			preRntPct:prjQuatPrps.preRntPct,
	 			isBp:prjQuatPrps.isBp,
	 			businessInsCd:prjQuatPrps.businessInsCd,
                tenThouCoef:prjQuatPrps.tenThouCoef,
	 			policyTypCd:prjQuatPrps.policyTypCd,
				oneCityOnePolicyTypeCd:prjQuatPrps.oneCityOnePolicyTypeCd,
				rentAllowanceService:prjQuatPrps.rentAllowanceService
	 		 });
	 		$("#prpsCfgId").val(prjQuatPrps.prpsCfgId);
	 		$("#isAllowChg").val(prjQuatPrps.isAllowChg);
	 		$("#isAllowAdd").val(prjQuatPrps.isAllowAdd);

	 		$("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
	 		$("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
			$("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
			$("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
			$("#splitPctValue").val(prjQuatPrps.quatSplitPct);//拆分比例
			annIntRatePct = prjQuatPrps.annIntRatePct;

			// 查看方案时，捆绑租金补助服务  重卡事业部，传统/城配 我司重卡灵活报价方案 显示，不可编辑
			rentAllowanceServiceIsShow(prjQuatPrps);
	 		setRentPeriod();
	 		var isAllowAdd = $("#isAllowAdd").val();
	 		if(isAllowAdd&&isAllowAdd==CommonConstant.C_YN_N){
	 			$("#addBtn").hide();
	 			$("#delBtn").hide();
	 		}
			if(prjQuatPrps.payWayCd==ProjectConstant.CODE_MULTI_STEP_INTER_19){
				$("#speLsPdDiv").show();
			}else{
				$("#speLsPdDiv").hide();
			}
	 		var isBp = $("#isBp").val();
	 		if(isBp==1){
	 			showBusinessIns();
	 		}
	 		var payWayCd = prjQuatPrps.payWayCd;
	 	 	if(payWayCd&&(payWayCd==ProjectConstant.CODE_END_NO_EQUAL||payWayCd==ProjectConstant.CODE_BEGI_NO_EQUAL)&&(detailFlag!="true")){
				$("#recovery").show();
			}else{
				$("#recovery").hide();
			}
		//初始化费用明细
	  var url = '<%=path%>/project/prjquatprps/getPrjQuatDetailById.do?id='+prpsId+'&&prjId='+prjId;
		prjQuatPrpsfeeGrid(url,editFlag,0);
		//初始化支付表明细
			var flag = false;
			var payWay = prjQuatPrps.payWayCd;
			if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
				flag = true;
			}
			initCalculatePage(flag);
	}else{
        if(compensatoryType == '2'){
            $("#chlDpstPwayCdDiv").show();
            $("#chlDpstRtnPdDiv").show();
            $("#chlDpstPwayCd").ligerGetComboBoxManager().setValue(" ");
            $("#rtnPdStart").ligerGetComboBoxManager().setValue("1");
            $("#rtnPdEnd").ligerGetComboBoxManager().setValue("6");
        }
        //厂商业务设置费用项不可修改
        if(isSplMfr == '1'){
            var prpsCfgId = $("#prpsCfgId").val();
            var url= '<%=path%>/project/prjquatprps/prjQuatPrpsCfgDInitList.do?prjId='+prjId+'&&prpsCfgId='+prpsCfgId;
            prjQuatPrpsfeeGrid(url,editFlag,0);
            //设置默认值
            var calQuatPrps = '${calQuatPrps}';
            if(calQuatPrps){
                calQuatPrps = JSON.parse(calQuatPrps);
                //初始化修改数据
                var form = liger.get("formSet1");
                if(ProjectConstant.CODE_DS_CD_JC == dsCd){
					form.setData({
						//totLsItmAmt:calQuatPrps.totLsItmAmt,
						//contAmt:calQuatPrps.contAmt,
						intRateRsPct:parseFloat(calQuatPrps.intRateRsPct==null?0:calQuatPrps.intRateRsPct),
						lsPd:calQuatPrps.lsPd,
						lsPdUntCd:calQuatPrps.lsPdUntCd,
						annIntRatePct:parseFloat(calQuatPrps.annIntRatePct==null?0:calQuatPrps.annIntRatePct),
						payWayCd:calQuatPrps.payWayCd,
						//actLsAmt:calQuatPrps.actLsAmt,
						eachEstRntAmt:calQuatPrps.eachEstRntAmt,
						speLsPd:calQuatPrps.speLsPd,
						lsCalWayCd:calQuatPrps.lsCalWayCd,
						irrPct:calQuatPrps.irrPct,
						irrPct2:calQuatPrps.irrPct2
					});
					var selectid= $("#rentAllowanceService").ligerGetComboBoxManager();
					selectid.setValue(0);
					selectid.setText('否');
					liger.get("rentAllowanceService").setDisabled(true);
				}else{
					form.setData({
						totLsItmAmt:calQuatPrps.totLsItmAmt,
						contAmt:calQuatPrps.contAmt,
						intRateRsPct:parseFloat(calQuatPrps.intRateRsPct==null?0:calQuatPrps.intRateRsPct),
						lsPd:calQuatPrps.lsPd,
						lsPdUntCd:calQuatPrps.lsPdUntCd,
						annIntRatePct:parseFloat(calQuatPrps.annIntRatePct==null?0:calQuatPrps.annIntRatePct),
						payWayCd:calQuatPrps.payWayCd,
						actLsAmt:calQuatPrps.actLsAmt,
						eachEstRntAmt:calQuatPrps.eachEstRntAmt,
						speLsPd:calQuatPrps.speLsPd,
						lsCalWayCd:calQuatPrps.lsCalWayCd,
						irrPct:calQuatPrps.irrPct,
						irrPct2:calQuatPrps.irrPct2
					});
				}
				if(calQuatPrps.payWayCd==ProjectConstant.CODE_MULTI_STEP_INTER_19){
					$("#speLsPdDiv").show();
				}else{
					$("#speLsPdDiv").hide();
				}
            }
        }else{
            if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK &&(prjTypCd==ProjectConstant.PRJ_TYP_CD_CDDYWUL||prjTypCd==ProjectConstant.PRJ_TYP_CD_ESCJYD) || prjTypCd == ProjectConstant.PRJ_TYP_CD_OWNJYD){
                var prpsCfgId = $("#prpsCfgId").val();
                var url= '<%=path%>/project/prjquatprps/cddPrjQuatPrpsCfgDInitList.do?prjId='+prjId+'&prpsCfgId='+prpsCfgId+"&editFlag=" + editFlag + "&prpsId=" + prpsId;
                prjQuatPrpsfeeGrid(url,editFlag,0);
            }else{
                var prpsCfgId = $("#prpsCfgId").val();
                var url= '<%=path%>/project/prjQuatPrpsCfgD/initList.do?prjId='+prjId+'&&prpsCfgId='+prpsCfgId;
                prjQuatPrpsfeeGrid(url,editFlag,0);
            }
        }


	}

	//设置拆分比例的值
	var  payWayCd = $("#payWayCd").val();
	if(payWayCd){
	     setSplitDefValue();
	}
	//isAllowChg 设置form字段是否可以修改
	//是否允许变更（5位标识位，1：租赁期数，2：支付方式，3：保证金处理方式，4：租赁期满处理方式，5：租赁年利率）
	var isAllowChg = $("#isAllowChg").val();
	if(isAllowChg){
	  var isAllowChgStr= new Array();
	  isAllowChgStr=isAllowChg.split(";");//字符分割
		for (i=0;i<isAllowChgStr.length ;i++ )
		{
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_LS_PD){
				//租赁期数
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					$("#lsPd").attr("readonly","readonly");
					  liger.get("lsPdUntCd").setDisabled(true);
				}
			}
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_PAY_WAY){
				//支付方式
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					  liger.get("payWayCd").setDisabled(true);
					}
			}
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_DPST_HDL_WAY){
				//保证金处理方式
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					  liger.get("dpstHdlWayCd").setDisabled(true);
				}
			}
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_EXP_HDL_WAY){
				//租赁期满处理方式
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					 liger.get("expHdlWayCd").setDisabled(true);
				}
			}
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_ANNINT_RATE_PCT){
				//租赁年利率
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					$("#annIntRatePct").attr("readonly","readonly");
				}
			}
		}

	}

 	 $('#annIntRatePct').toFixNumber(annIntScale,
	            {
	                onToFix: function () {
	                    $.ligerDialog.SQalert({SQ_type: "warning", content: "小数点后不要超过"+annIntScale+"位数！"});
	                }
	        }
	 );
	 $('#intRateRsPct').toFixNumber(floatScale,
	            {
	                onToFix: function () {
	                    $.ligerDialog.SQalert({SQ_type: "warning", content: "小数点后不要超过"+floatScale+"位数！"});
	                }
	        }
	 );
	$("#calculateBtn1").click(function(event) {
		var flag = false;
		var payWay = $("#payWayCd").val();
		if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
			flag = true;
		}
		initCalculateGrid(flag);
	 });

	$("#saveBtn1").click(function(event) {
	    var form = liger.get("formSet1");
	    if (!form.valid()) {
	    	$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
            return false; //验证不通过，不执行以下代码
        }
	    saveQuat();


});

	function saveQuat(){
		// (厂商业务-城配 or 厂商业务-传统) 需要选择方案政策类型
        if ((prjTypCd==ProjectConstant.PRJ_TYP_CD_CPYW && isSplMfr == '1')||(prjTypCd==ProjectConstant.PRJ_TYP_CD_CTYW && isSplMfr == '1')) {
            if ($("#policyTypCd").val() == "") {
                $.ligerDialog.SQalert({content: "请选择方案政策类型！", SQ_type: "warning"});
                return;
            }
        }
	    //判断是否满足阶梯还款条件
	    var payTypCd = $("#payWayCd").val();
        var isBp = $("#isBp").val();
        var payTax;//购置税
        var insurance;//保险费
        var rsrvPcValue;//留购价
		var invoiceValue;

		var rows = feeGrid.rows;
		if (rows) {
			for (var i = 0; i < rows.length; i++) {
				var feeTypCd = rows[i].feeTypCd;
				if (feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_30) {
					payTax = rows[i].feeAmt;
				}
				if (feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_67) {
					insurance = rows[i].feeAmt;
				}
				if (feeTypCd==ProjectConstant.PRJ_FEE_TYP_PURCHASE) {
					rsrvPcValue = rows[i].feeAmt;
				}
			}
		}
		/**
		 *  REQ-14544 平安银行是否包牌校验逻辑调整
		 *  是否包牌字段选否或者包购置税时，【购置税】、【保险费】字段可编辑，保存报价方案时，
		 *  【购置税】、【保险费】字段均必须>0；否则提示“平安银行资管业务【购置税】、【保险费】必填”
		 */
		if (ProjectConstant.PRJ_INS_CODE_PABANK == insCode) {
			if (payTax <= 0.00 || insurance <= 0.00 || payTax == '' || insurance == '') {
				top.$.ligerDialog.SQalert({content: "平安银行资管业务【购置税】、【保险费】必填", SQ_type: "warning"});
				return false;
			}
		} else {
			if ((payTax <= 0.00 || payTax == '') &&
					(ProjectConstant.PRJ_INS_CODE_SHNSBANK == insCode || ProjectConstant.PRJ_INS_CODE_PSD == insCode)) {
				/**
				 * 上海农商银行,浦发
				 * 购置税不能小于等于0
				 */
				top.$.ligerDialog.SQalert({content: "购置税小于等于0，请重新填写！", SQ_type: "warning"});
				return false;
			}
			if ((insurance <= 0.00 || insurance == '')
					&& (ProjectConstant.PRJ_INS_CODE_SHNSBANK == insCode)) {
				/**
				 *  上海农商银行
				 *  保险费不能小于等于0
				 */
				top.$.ligerDialog.SQalert({content: "保险费小于等于0，请重新填写！", SQ_type: "warning"});
				return false;
			}
			if (rsrvPcValue != 0.00 && rsrvPcValue == '' && ProjectConstant.PRJ_INS_CODE_ZYFL == insCode) {
				/**
				 *  浙银机构
				 *  留购价必须为0
				 */
				top.$.ligerDialog.SQalert({content: "留购价必须为0，请修改", SQ_type: "warning"});
				return false;
			}
			/**
			 * 根据是否包牌对购置税和保险费进行通用判断
			 */
			if (isBp == '1') {
				// 判断 是否包牌价是包购置税时需填写购置税
				if (payTax <= 0.00 || payTax == '') {
					top.$.ligerDialog.SQalert({content: "请填写购置税", SQ_type: "warning"});
					return false;
				}
			} else if (isBp == '2') {
				// 判断 是否包牌价是包购置税和保险时需填写购置税和保险
				if (payTax <= 0.00 || insurance <= 0.00 || payTax == '' || insurance == '') {
					top.$.ligerDialog.SQalert({content: "请填写购置税；请填写保险费", SQ_type: "warning"});
					return false;
				}
			} else if (isBp == '3') {
				// 判断 是否包牌价是保险时需填写保险
				if (insurance <= 0.00 || insurance == '') {
					top.$.ligerDialog.SQalert({content: "请填写保险费", SQ_type: "warning"});
					return false;
				}
			}
		}

		// 传统/城配项目，我司首期款比例不能小于10%
		if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK && CommonConstant.C_YN_N == isInsBiz
				&& (prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW || prjTypCd == ProjectConstant.CODE_PRJ_TYP_CD_CPYW)){
			var rows = feeGrid.rows;
			for (var i = 0; i < rows.length; i++) {
				if(rows[i].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_01 &&  rows[i].feePct < 10){
					top.$.ligerDialog.SQalert({content: "首期比例不能小于10%", SQ_type: "warning"});
					return false ;
				}
			}
		}
		if(compensatoryType == '2'){
			if (!$("#chlDpstPwayCd").val() || $("#chlDpstPwayCd").val() == ' '){
				top.$.ligerDialog.SQalert({content: "请选择渠道保证金退还方式", SQ_type: "warning"});
				return false ;
			}
		}
        var lsPd = $("#lsPd").val();
		//重卡除厂商业务判断咨询费(供返)+咨询费(销返)是否小于等于供应商返利
        if(((buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK)||buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZC)&&!((prjTypCd==ProjectConstant.PRJ_TYP_CD_CPYW && isSplMfr == '1')||(prjTypCd==ProjectConstant.PRJ_TYP_CD_CTYW && isSplMfr == '1'))){
		 			  var rows = feeGrid.rows;
		 			  var splBack=0;//供应商返利 
		 			  var consltSplBack=0;//咨询费供应商返利
		 			  var consltSalBak =0;//咨询费销售返利
		 			  if(rows){
		  				 for (var i = 0; i < rows.length; i++) {
		  				  			var feeTypCd = rows[i].feeTypCd;
		  					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_05){
		  						splBack = (parseFloat(rows[i].feeAmt)).toFixed(2);
		  			  			}
		  					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_71){
		  						consltSplBack = (parseFloat(rows[i].feeAmt)).toFixed(2);
		      			  		}
		  					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_72){
		  						consltSalBak = (parseFloat(rows[i].feeAmt)).toFixed(2);
		      			  		}
		  				 }
		  				 if(parseFloat(consltSplBack)+parseFloat(consltSalBak)>parseFloat(splBack)){
		  					UIUtils.alertWarningHold1("咨询费(供返)与咨询费(销返)之和不能大于咨询费2金额！");
		  					return;
			             		//  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "咨询费(供返)与咨询费(销返)之和不能大于咨询费2金额！"});
		  				 }
		 			  }
		 	 }
		  if(payTypCd&&payTypCd==ProjectConstant.CODE_PAY_QUAT_MULTI_STEP){
				$.ajax({
					type: 'get',
					dataType:'json',
					data:{"payPd":lsPd,
						"prjId":prjId},
					url: '<%=path%>/project/prjquatprps/checkMultiStepStatus.do',
					success:function(msg){
						 if(msg.success!=1){
							 $.ligerDialog.SQalert({content: "不可选择该支付方式，请选择其他支付方式", SQ_type: "warring"});
								return;
						 }else{
	    var id = $("#prpsId").val();
	    //修改时判断是否有支付表，有就提示是否删除支付表
			//查询是否有支付表信息
			if($("#prpsId").length){
				var params = {};
				params.prjId=prjId;
				$.ajax({
					type: 'get',
					dataType:'json',
					data:params,
					url: '<%=path%>/project/prjprdpayschm/getPrjPrdPayByPrjId.do',
					success:function(msg){
						 if(msg.data){
								$.ligerDialog.confirm("已经存在支付表信息，修改方案后需要重新拆分支付表，确定修改方案，重新拆分支付表吗？", function (flag) {
									if(flag == false)return;
									addPrjQuatPrps();
								});
						 }else{
							 addPrjQuatPrps();
						 }
					}
				});


			}else{
				addPrjQuatPrps();
			}
						 }
					  }
					});
	}else{

		   var id = $("#prpsId").val();
		    //修改时判断是否有支付表，有就提示是否删除支付表
				//查询是否有支付表信息
				if($("#prpsId").length){
					var params = {};
					params.prjId=prjId;
					$.ajax({
						type: 'get',
						dataType:'json',
						data:params,
						url: '<%=path%>/project/prjprdpayschm/getPrjPrdPayByPrjId.do',
						success:function(msg){
							 if(msg.data){
									$.ligerDialog.confirm("已经存在支付表信息，修改方案后需要重新拆分支付表，确定修改方案，重新拆分支付表吗？", function (flag) {
										if(flag == false)return;
										addPrjQuatPrps();
									});
							 }else{
								 addPrjQuatPrps();
							 }
						}
					});


				}else{
					addPrjQuatPrps();
				}
	}
	}
/* 	var contAmt=$("#contAmt").val();
	if(contAmt){
	changeBaseContAmt();
	}
	 var totLsItmAmt=$("#totLsItmAmt").val();
	if(totLsItmAmt){
	 changeBaseTotLsltmAmt();
	} */


	function addPrjQuatPrps(){
		    var form = liger.get("formSet1");
		    if (!form.valid()) {
	            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
	            return false; //验证不通过，不执行以下代码
	        }
		  var data = form.getData();
		  //判断是否满足阶梯还款条件
		  var payTypCd = $("#payWayCd").val();
		  var lsPd = $("#lsPd").val();
							   var detailListData = feeGrid.getData();
							    var calculateData;
							    if(calculateGrid){
							     calculateData = calculateGrid.getData();
							    }
							    var id = $("#prpsId").val();
					         data["id"]= id;
					         data["prjId"] = prjId;
					         data["lsPdUntCd"]=$("#lsPdUntCd").val();
					         data["payWayCd"]=$("#payWayCd").val();
					         data["lsCalWayCd"]=$("#lsCalWayCd").val();
					         data["intRateWayCd"]=$("#intRateWayCd").val();
					         data["dpstHdlWayCd"]=$("#dpstHdlWayCd").val();
					         data["expHdlWayCd"]=$("#expHdlWayCd").val();
					         data["noPayWayCd"]=$("#noPayWayCd").val();
					         data["prpsCfgId"]=$("#prpsCfgId").val();
					         data["prpsCfgNm"]=$("#prpsCfgNm").val();
					         data["isAllowChg"]=$("#isAllowChg").val();
					         data["isAllowAdd"]=$("#isAllowAdd").val();
					         data["prpsTypCd"]=prpsTypCd;
					         data["prpsCfgId"]=$("#prpsCfgId").val();
					         data["mfrDiscountRate"]=$("#mfrDiscountRate").val();
					         data["policyTypCd"]=$("#policyTypCd").val();
					     	 data["feeDetailList"] = JSON.stringify(detailListData);
					  	 	 data["payList"] = JSON.stringify(calculateData);
					  	 	 // 是否使用专享额度产品
							 data["isLowDownPayment"] = $("#isLowDownPayment").val();
        					//是否低息
        					//data["isLowBiz"] = $("#isLowBiz").val();
							data["isLowBiz"] = $("#isLowBiz_txt_val").val();
        					//是否需要弹窗提示
							data["isNeedOpenWin"] = '0';
							// 租金补助服务
							data['rentAllowanceService'] =  $("#rentAllowanceService").val();
							data['chlDpstPwayCd'] = $("#chlDpstPwayCd").val();
							data['rtnPdStart'] = $("#rtnPdStart").val();
							data['rtnPdEnd'] = $("#rtnPdEnd").val();
					  var url = '<%=path%>/project/prjquatprps/addQuatPrps.do';
					  var wait_dialog;
					  $.ajax({
							type: 'post',
							dataType:'json',
							data:data,
							url: url,
							beforeSend: function(){
						          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
						     },
							success:function(msg){
								 wait_dialog.close();
								 if(msg.success == 1){
									 smallLoanAmt(msg);
								 }else{
								 	if(!msg.data.isNeedOpenWin ||  msg.data.isNeedOpenWin == 1){
										$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
									}else{
										$.ligerDialog.confirm("该项目支持保证金抵租金流程，是否使用？（特殊业务类型需包含低息业务）", function (flag) {
											if (flag == true)return;
											data["isNeedOpenWin"] = '1';
											var wait_dialog;
											$.ajax({
												type: 'post',
												dataType:'json',
												data:data,
												url: url,
												beforeSend: function(){
													wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
												},
												success:function(msg){
													wait_dialog.close();
													if(msg.success == 1){
														smallLoanAmt(msg);
													}else{
														$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
													}
												}
											});
										});
									}
								 }
							}
						});
		  }
	function smallLoanAmt(msg){
		if(msg.data && msg.data.code == 10000 && msg.data.smallLoanAmt > 0){
			$("#smallLoanAmt").val(msg.data.smallLoanAmt).parent().parent().parent().show();
			var isLowDownPaymentId= $("#isLowDownPayment").ligerGetComboBoxManager();
			if(prjQuatPrps && prjQuatPrps.isLowDownPayment){
				isLowDownPaymentId.setValue(prjQuatPrps.isLowDownPayment);
			}else{
				$("#isLowDownPayment").parent().parent().show();
				$("#isLowDownPayment_txt").val("--请选择--");
			}
			$.ligerDialog.SQopen({
				width: 800,
				top: 100,
				buttons: [
					{
						text: "确定", cls: 'l-dialog-btn-no', onclick:function(){
							$.ligerDialog.hide();
						}
					}
				],
				title : '请选择是否申请专享额度',
				content:"经测算，您的专享可用额度为" + msg.data.smallLoanAmt + "，请选择是否申请专享额度。"
			});
			return false;
		}
		prjQuatPrps = msg.data;
		if(prjQuatPrps.isShowIns == CommonConstant.C_YN_Y){
			$.ligerDialog.SQopen({
				width: 800,
				top: 100,
				buttons: [
					{
						text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
							$.ligerDialog.hide();
						}
					}
				],
				title : '机构筛选结果',
				target: $("#res_div")
			});
			isAllowNonIns = prjQuatPrps.isAllowNonIns;
			if(isAllowNonIns == CommonConstant.C_YN_Y){
				$("#isAllowNonIns").html("特批标识：是");
			}else{
				$("#isAllowNonIns").html("特批标识：否");
			}
			if(prjQuatPrps.gctInsResList == null || !(prjQuatPrps.gctInsResList.length>0)){
				$("#defaultText").show();
				$("#defaultTip").hide();
			}else{
				$("#defaultText").hide();
				$("#defaultTip").show();
			}
			ligerGrid_heguijigou.loadData({rows:prjQuatPrps.gctInsResList});
			ligerGrid_heguijigouUn.loadData({rows:prjQuatPrps.ungctInsResList});
		}else{
			$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
			if(msg.data.id){
				$("#prpsId").val(msg.data.id);
				if(isFlow&&isFlow=='1'){

					$.ligerDialog.SQalert({
						SQ_showButtons: true,
						SQ_onBtnclick: function (item, Dialog) {
							var TAB=top.mainApp.parentTab;
							var currentTabid=TAB.getSelectedTabItemID();
							var currFrameElement=top.$("#"+currentTabid).get(0);
							var callback=currFrameElement.W2W.callback;
							callback();
							top.tab.removeTabItem(currentTabid);
						},
						content: "保存成功！请核实支付表明细及产品明细信息是否准确!"
					});

					//top.$.ligerDialog.SQalert({content: "保存成功！请核实支付表明细及产品明细信息是否准确!",SQ_type: "success"});
				}else{
					top.$.ligerDialog.SQalert({content: "保存成功！",SQ_type: "success"});
					var TAB=top.mainApp.parentTab;
					var currentTabid=TAB.getSelectedTabItemID();
					var currFrameElement=top.$("#"+currentTabid).get(0);
					var callback=currFrameElement.W2W.callback;
					callback();
					top.tab.removeTabItem(currentTabid);
				}

			}
		}
	}
	$("#addBtn").click(function (event) {
        feeGrid.addRow({
        	feeTypCd: '',
        	calBaseCd: '',
        	feePct: 0,
        	feeAmt:0,
        	cntWayCd: '',
        });
    });
	$("#delBtn").click(function (event) {
        var selectedRows = feeGrid.getSelectedRows();
        if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		for ( var index in selectedRows) {
			if(selectedRows[index].isSysDef){
				if(selectedRows[index].isSysDef==CommonConstant.C_YN_Y){
					$.ligerDialog.SQalert({content: "不允许删除方案配置费用项", SQ_type: "warring"});
					return;
				}
			}
		}
        feeGrid.deleteSelectedRow();
    });
	if(detailFlag=="true"){
		if($("#prpsCfgNm")){
			$("#prpsCfgNm").attr("readonly","readonly");
		}
		if($("#totLsItmAmt")){
			$("#totLsItmAmt").attr("readonly","readonly");
		}
		if($("#contAmt")){
			$("#contAmt").attr("readonly","readonly");
		}
		if($("#lsPd")){
			$("#lsPd").attr("readonly","readonly");
		}
		if($("#annIntRatePct")){
			$("#annIntRatePct").attr("readonly","readonly");
		}
		if($("#actLsAmt")){
			$("#actLsAmt").attr("readonly","readonly");
		}
		if($("#eachEstRntAmt")){
			$("#eachEstRntAmt").attr("readonly","readonly");
		}
		if($("#lsCoe")){
			$("#lsCoe").attr("readonly","readonly");
		}
		if($("#intRateRsPct")){
			$("#intRateRsPct").attr("readonly","readonly");
		}

		if(liger.get("lsPdUntCd")){
			  liger.get("lsPdUntCd").setDisabled(true);
		}
		if(liger.get("payWayCd")){
			  liger.get("payWayCd").setDisabled(true);
		}
		if(liger.get("lsCalWayCd")){
			  liger.get("lsCalWayCd").setDisabled(true);
		}
		if(liger.get("intRateWayCd")){
			  liger.get("intRateWayCd").setDisabled(true);
		}
		if(liger.get("dpstHdlWayCd")){
			  liger.get("dpstHdlWayCd").setDisabled(true);
		}
		if(liger.get("expHdlWayCd")){
			  liger.get("expHdlWayCd").setDisabled(true);
		}
		if(liger.get("noPayWayCd")){
			  liger.get("noPayWayCd").setDisabled(true);
		}
		if(liger.get("preRntPct")){
			  liger.get("preRntPct").setDisabled(true);
		}
		if (liger.get("chlDpstPwayCd")){
			liger.get("chlDpstPwayCd").setDisabled(true);
		}
		if (liger.get("rtnPdStart")){
			liger.get("rtnPdStart").setDisabled(true);
		}
		if (liger.get("rtnPdEnd")){
			liger.get("rtnPdEnd").setDisabled(true);
		}
		if (liger.get("oneCityOnePolicyTypeCd")){
			liger.get("oneCityOnePolicyTypeCd").setDisabled(true);
		}
	}
	//如果配置方案不可添加，隐藏费用添加、删除按钮]
	var isAllowAdd = $("#isAllowAdd").val();
	if(isAllowAdd==CommonConstant.C_YN_N){
		$("#addBtn").hide();
		$("#delBtn").hide();
	}

	ligerGrid_heguijigou = $("#grid_heguijigou").ligerGrid({
		url: '<%=path%>/insroute/insRouteBscInfo/insRoute.do',
		method : 'post',
		parms:{
			sts:CommonConstant.C_YN_Y
		},
		columns: [
			{ display: '合规机构名称', name: 'insNm', width: 300,
                render: function (rowdata, index, value) {
			        if (rowdata.insId && ("" + rowdata.insId).trim()) {
                        if(arrFoundCode){
                            for (var i=0;i<arrFoundCode.length;i++) {
                                if(arrFoundCode[i].fundRasInsId == rowdata.insId){
                                    return '<span style="font-weight: bold">' + arrFoundCode[i].fundRasInsNmShow + '</span><br/>';
                                }
                            }
                        }
					}else{
                        return '<span style="font-weight: bold">' + rowdata.insNm + '</span><br/>';
                    }
                }
			},
			{ display: '提示信息', name: 'gctDes', align: 'left',
				render:function(rowdata,rowindex,value){
					if(rowdata.gctDes!=null){
						return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.gctDes + '">' + rowdata.gctDes + '</span>';
					}
				} },
			{ display: '追加调节费', name: 'feeDes', align: 'left',
				render:function(rowdata,rowindex,value){
					if(rowdata.feeDes!=null){
						return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.feeDes + '">' + rowdata.feeDes + '</span>';
					}
				}
			},
		],
		pageSize:10,
		hideLoadButton : true,
		width: '100%',
		root: 'rows',
		record: 'total',
		// height: 250,
		checkbox:true,
		rownumbers:true,
		usePager: false,
		frozen: false,
		fixedCellHeight: false,
		isSingleCheck: true,
		isChecked:function(item){
			if (item.isChecked == CommonConstant.C_YN_Y)
				return true;
			return false;
		},
		isDisabledSelect: function (item) {
			if (item.Country == 'UK' || item.Country == 'Mexico') return true;
		},
		onAfterShowData: function (item) {
			SetIframe_height ();
		},
		onLoaded:function(){
			this.toggleLoading(false);
		},
	});
	ligerGrid_heguijigouUn = $("#grid_heguijigouUn").ligerGrid({
		url: '<%=path%>/insroute/insRouteBscInfo/insRoute.do',
		method : 'post',
		parms:{
			sts:CommonConstant.C_YN_N
		},
		columns: [
            { display: '不合规机构名称', name: 'insNm', width: 300,
                render: function (rowdata, index, value) {
                    if (rowdata.insId && ("" + rowdata.insId).trim()) {
                        if(arrFoundCode){
                            for (var i=0;i<arrFoundCode.length;i++) {
                                if(arrFoundCode[i].fundRasInsId == rowdata.insId){
                                    return '<span style="font-weight: bold">' + arrFoundCode[i].fundRasInsNmShow + '</span><br/>';
                                }
                            }
                        }
					}else{
                        return '<span style="font-weight: bold">' + rowdata.insNm + '</span><br/>';
                    }
                }
            },
			{ display: '提示信息', name: 'gctDes', align: 'left',
				render:function(rowdata,rowindex,value){
					if(rowdata.gctDes!=null){
						return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.gctDes + '">' + rowdata.gctDes + '</span>';
					}
			} },
		],
		pageSize:10,
		hideLoadButton : true,
		width: '100%',
		root: 'rows',
		record: 'total',
		// height: 250,
		checkbox:false,
		rownumbers:true,
		usePager: false,
		frozen: false,
		fixedCellHeight: false,
		isSingleCheck: true,
		isDisabledSelect: function (item) {
			if (item.Country == 'UK' || item.Country == 'Mexico') return true;
		},
		onAfterShowData: function () {
			SetIframe_height ();
		},
		onLoaded:function(){
			this.toggleLoading(false);
		},
		onsuccess:function (data) {
			if(data.rows.length>0){
				for (index in data.rows) {
					if(data.rows[index].isShowBiz == CommonConstant.C_YN_N){
						ligerGrid_heguijigouUn.deleteRow(data.rows[index]);
					}
				}
			}
		}
	});

    /**
	 * 申请特批
	 */
	$('#applySpecial').click(function(event) {
		var onOk = function (item, Dialog) {
			if($("#docketRem").val() == ""){
				top.$.ligerDialog.SQalert({content: "发起特批流程原因为空", SQ_type: "warning"});
				return false;
			}
			confirmBtn(CommonConstant.C_YN_Y);
			Dialog.hide();
		};
		var onCancel = function (item, Dialog) {
			Dialog.hide();
		};
		var len = ligerGrid_heguijigou.getData().length;
		var selectedRows = ligerGrid_heguijigou.getSelectedRows();
		if(len > 0 && !(selectedRows.length > 0)){
			//一、（强校验）  1.重卡项目类型：城配业务、传统业务    二、（弱校验）  1.专车事 业部项目类型：客车业务  2.新能源汽车项目类型：城配业务 3.其他
			if(buOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK
					&& (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW
							|| prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)){
				if(!(isAllowNonIns == CommonConstant.C_YN_Y)){//特批
					$.ligerDialog.SQopen({
						width: 450,
						title : '申请特批',
						target : $('#capFundConfirm_form'),
						buttons: [
							{
								text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
							},{
								text: "申请特批", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
							}
						]
					});
				}else{
					top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
					return false; //验证不通过，不执行以下代码
				}
			}else{
				top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
				return false; //验证不通过，不执行以下代码
			}
		}else{
			if((preInsId != "" && preInsId != null) && len == 0){
				if(buOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK
						&& (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW
								|| prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)){
					if(!(isAllowNonIns == CommonConstant.C_YN_Y)){//特批
						$.ligerDialog.SQopen({
							width: 450,
							title : '申请特批',
							target : $('#capFundConfirm_form'),
							buttons: [
								{
									text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
								},{
									text: "申请特批", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
								}
							]
						});
					}else{
						top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
						return false; //验证不通过，不执行以下代码
					}
				}
			}else{
				top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
				return false; //验证不通过，不执行以下代码
			}
		}
	});
    $("#specialBusinessType").change(function(){
        var value = $(this).val();
        console.log(value);
        var selectid= $("#isLowBiz").ligerGetComboBoxManager();
        if(value == '3'){
            selectid.setValue(1);
        }else{
            selectid.setValue(0);
        }
		/*if(value == '3'){
            $("#isLowBiz").val('1').attr('disabled',true);
        }else{
            alert(0);
            $("#isLowBiz").val('0').attr('disabled',true);
        }*/
        liger.get("isLowBiz").setDisabled(true);
    });
    /**
	 * 保存路由数据
	 */
	$('#confirmBtn').click(function(event) {
		var onOk = function (item, Dialog) {
			if($("#docketRem").val() == ""){
				top.$.ligerDialog.SQalert({content: "发起特批流程原因为空", SQ_type: "warning"});
				return false;
			}
			confirmBtn(CommonConstant.C_YN_Y);
			Dialog.hide();
		};
		var onCancel = function (item, Dialog) {
			Dialog.hide();
		};
		var len = ligerGrid_heguijigou.getData().length;
		var selectedRows = ligerGrid_heguijigou.getSelectedRows();
		if(len > 0 && !(selectedRows.length > 0)){
			//一、（强校验）  1.重卡项目类型：城配业务、传统业务    二、（弱校验）  1.专车事 业部项目类型：客车业务  2.新能源汽车项目类型：城配业务 3.其他
			if(buOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK
					&& (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW
							|| prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)){
				if(!(isAllowNonIns == CommonConstant.C_YN_Y)){//特批
					$.ligerDialog.SQopen({
						width: 450,
						title : '申请特批',
						target : $('#capFundConfirm_form'),
						buttons: [
							{
								text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
							},{
								text: "申请特批", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
							}
						]
					});
				}else{
					confirmBtn(CommonConstant.C_YN_N);
				}
			}else{
				confirmBtn(CommonConstant.C_YN_N);
			}
		}else{
			if((preInsId != "" && preInsId != null) && len == 0){
				if(buOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK
						&& (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW
								|| prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)){
					if(!(isAllowNonIns == CommonConstant.C_YN_Y)){//特批
						$.ligerDialog.SQopen({
							width: 450,
							title : '申请特批',
							target : $('#capFundConfirm_form'),
							buttons: [
								{
									text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
								},{
									text: "申请特批", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
								}
							]
						});
					}else{
						top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
						return false; //验证不通过，不执行以下代码
					}
				}
			}else{
				confirmBtn(CommonConstant.C_YN_N);
			}
		}
	});

	function confirmBtn(spemak) {
		var onCancel = function (item, Dialog) {
			Dialog.hide();
		};
		var onConfirmBtn = function (item, Dialog) {
			Dialog.hide();
			save(spemak);
		};
		$.ligerDialog.SQopen({
			width: 450,
			title : '友情提示',
			target : $('#confirm_form'),
			buttons: [
				{
					text: "确认", onclick: onConfirmBtn, type: 'ok', cls: 'l-dialog-btn-ok'
				},{
					text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
				}
			]
		});
	}

	function save(marks) {
		var data = {};
		data["contAmt"] = $("#contAmt").val();
		data["isBp"] = $("#isBp").val();
		data["lsPd"] = $("#lsPd").val();
		data["annIntRatePct"] = $("#annIntRatePct").val();
		var feeList = JSON.stringify(feeGrid.getData());
		var jigou = ligerGrid_heguijigou.getData();
		if(ligerGrid_heguijigouUn.getDeleted() != undefined || ligerGrid_heguijigouUn.getDeleted() != null){
			jigou = jigou.concat(ligerGrid_heguijigouUn.getDeleted());
		}
		jigou = jigou.concat(ligerGrid_heguijigouUn.getData());
		var insResList = JSON.stringify(jigou);
		data["prjId"] = prjId;
		data["isSplMfr"] = isSplMfr;
		data["channel"] = CommonConstant.C_YN_Y;
		if(marks == CommonConstant.C_YN_Y){
			data["isSpecial"] = CommonConstant.C_YN_Y;
			data["reason"] = $("#docketRem").val();
		}else{
			data["isSpecial"] = CommonConstant.C_YN_N;
		}
		data["feeList"] = feeList;
		data["insResList"] = insResList;
		var selectedRows = ligerGrid_heguijigou.getSelectedRows();
		if(selectedRows.length > 0){
			data["checkedInsId"] = selectedRows[0].insId;
			data["checkedInsCode"] = selectedRows[0].insCode;
			data["checkedInsNm"] = selectedRows[0].insNm;
		}
		$.ajax({
			type: 'post',
			dataType:'json',
			data:data,
			url: '<%=path%>/insroute/insRouteBscInfo/save.do',
			success:function(msg){
				if(msg.success == CommonConstant.C_YN_Y){
					top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
					$.ligerDialog.hide();
					var closeFlag = CommonConstant.C_YN_N;
					var isBankShow = CommonConstant.C_YN_N;
					var fundRasInsId;
					var fundRasInsNm;
					var insCode;
					var title;
					if(selectedRows.length > 0){
						fundRasInsNm = selectedRows[0].insNm;
						fundRasInsId = selectedRows[0].insId;
						insCode = selectedRows[0].insCode;
						if (msg.data.sysInsTabCfgVO != null){
							title = msg.data.sysInsTabCfgVO.title;
							isBankShow = CommonConstant.C_YN_Y;
						}
					}
					if(marks == CommonConstant.C_YN_Y){
						closeFlag = CommonConstant.C_YN_Y;
					}
					var TAB=top.mainApp.parentTab;
					var currentTabid=TAB.getSelectedTabItemID();
					var currFrameElement=top.$("#"+currentTabid).get(0);
					var callback=currFrameElement.W2W.callback;
					top.tab.removeTabItem(currentTabid);
					callback(1,closeFlag,isBankShow,fundRasInsId,fundRasInsNm,insCode,title);
				}else{
					top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
				}
			}
		});
	}

});



function deleteRow(){
	var manager = $("#ligergrid_fee").ligerGetGridManager();
	 manager.deleteSelectedRow();
}

function prjQuatPrpsfeeGrid(url,editFlag,sts){
	feeGrid = $("#ligergrid_fee").ligerGrid({
		url:url,
        method: 'get',
        columns: [
            {display: '费用类型', name: 'feeTypCd', minWidth: 80,
                editor: {
                    type: 'select',
                    data: feeTypCdListJSON,
                    valueField: 'code',
                    textField: 'codeNm'
                },
                valueField: 'feeTypCd',
                textField: 'feeTypCdNm',
                render: function (item) {
                    return item.feeTypCdNm;
                }
            },
            {display: '是否为固定值', name: 'isFixedAmt', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: yesOrNoCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'isFixedAmt',
                textField: 'isFixedAmtNm',
                render: function (item) {
                    return item.isFixedAmtNm;
                }
            },
            {display: '计算基数', name: 'calBaseCd', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: calBaseCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'calBaseCd',
                textField: 'calBaseCdNm',
                render: function (item) {
                    return item.calBaseCdNm;
                }
            },

            {display: '比例值（%）', name: 'feePct', minWidth: 80, type: 'numberbox',

            	editor: {type: 'number',
            				precision:feeScale,
            				toFix:true,
            				onToFix:function(){
            					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多"+feeScale+"小数！"});
            				}
            		},
            render: function (item) {
            	if(item.isFixedAmt!=1){
            		item.feePct = Number(item.feePct);
	            	if(typeof item.feePct =='number'){
                        var pct =  (parseFloat(item.feePct)).toFixed(2)

                        return pct;
	            	}
            	}else{
            		if(item.feeTypCd=="54" && item.feePct != null){
           			var pct =  (parseFloat(item.feePct)).toFixed(2)
   	            	return pct;
            		}else{
            		    return 0;
            		}
            	}
            }
            	/*    render: function (e) {
            		  var feePct = 0;
            		   var minPct = e.feePctMin;
                    	var maxPct = e.feePctMax;
                    	var isFixedAmt =  e.isFixedAmt;
                    	var isAllowChg =e.isAllowChg;
                    	var calBaseCd =   e.calBaseCd;
                    	if(minPct&&maxPct){
                    	if(minPct==maxPct){
                    		//最大与最小值相等，设置为默认比例值
                    		e.value=minPct;
                    		e.feeAmt = getAmt(e.value,calBaseCd);
                    		e.feePct = e.value;
                    	}
                    	}
                    	if(e.feePct=="NaN"){
                    		feePct = 0;
            		 	}else{
                    	feePct = e.feePct;
            		 	}
                     return feePct;
                 }   */
            },
            {display: '金额（元）', name: 'feeAmt', minWidth: 80, render:renderAmt,type: 'numberbox',
            	editor: {type: 'number',
		            		precision:2,
		    				toFix:true,
		    				onToFix:function(){
           					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
           				}
            	}
               /*  render: function (item) {
             	   var quatPrps = '${id}';
            	   if(!quatPrps){
	                	if(item.isFixedAmt==1&&item.feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_PURCHASE){
	    	            	return totalRsrvPcStr;
	                	}else{
	                		return item.feeAmt;
	                	}
            	   }else{
            		   return item.feeAmt;
            	   }
            	   return item.feeAmt;
                } */
            },

            {display: '计入方式', name: 'cntWayCd', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: cntWayCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'cntWayCd',
                textField: 'cntWayCdNm',
                render: function (item) {
                    return item.cntWayCdNm;
                }
            }
/*             {
                display: '操作',
                isSort: false,
                width: 100,
                render: function (rowdata, rowindex, value){
                	 var h="";
                	if(rowdata.id==''||rowdata.isSysDef==0){
                		  h='<a class="sq-button-hasicon" href="javascript:deleteRow(';
                          h+=')"><i class="sqBtnIco_3"></i>删除</a>'
                	}

                    return h;
                }
            } */

        ],
       onLoaded:function(){
    	   var quatPrps = '${id}';
    	   if(sts == 0){
			   if(!quatPrps){
				   changeBaseTotLsltmAmt(0);
				   changeBaseContAmt(0);
			   }
		   }else{
			   changeBaseTotLsltmAmt(1);
			   changeBaseContAmt(1);
		   }
        	this.toggleLoading(false);
        },
        onBeforeEdit: function(e){
        	var colNanme = e.column.columnname;
	        	if(e.record.isAllowChg==0){
	        	    // if (colNanme == "cntWayCd" || colNanme == "calBaseCd"|| colNanme == "isFixedAmt"||colNanme == "feeTypCd") {
                  	   e.column.editor.readonly = true;
                   //}
        		}else{
        			e.column.editor.readonly = false;
        			if(e.record.isSysDef==1){
           		 	 //根据行数据里的"editable"属性，指定是否可以编辑这一行数据
                       if (colNanme == "cntWayCd" || colNanme == "calBaseCd"|| colNanme == "isFixedAmt"||colNanme == "feeTypCd") {
                    	   e.column.editor.readonly = true;
                       }
                       if(e.record.isFixedAmt==1){
                    	   if (colNanme == "feePct") {
                        	   e.column.editor.readonly = true;
                           }
           		 	 }else{
           		 	 if (colNanme == "feePct") {
                  	   e.column.editor.readonly = false;
                     }
           		 	 }
           			}else{
           		      if (colNanme == "cntWayCd" || colNanme == "isFixedAmt"||colNanme == "feeTypCd") {
                   	   e.column.editor.readonly = false;
                      }
           			 if(e.record.isFixedAmt==1){
               		 	 //根据行数据里的"editable"属性，指定是否可以编辑这一行数据
                           if (colNanme == "feePct" || colNanme == "calBaseCd") {
                               if (e.record.editable == 1) {
                                   e.column.editor.readonly = true;
                               }else{
                                   e.column.editor.readonly = false;
                               };
                           }
           			}else{
           		      if (colNanme == "feePct" || colNanme == "calBaseCd") {
                              e.column.editor.readonly = false;
                      }

           			}

        		}
        			//重卡非资管业务根据选择的是否包牌判断费用项的可读
        			if((buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK) || buOrgCd==ProjectConstant.CODE_BU_ORG_CD_XNY){
        				var isBp = $("#isBp").val();
        				var isBpCanWts = isBpCanWtsIns(insCode);
        				if(isBp&&isBp=='0'){
							if(e.record.feeTypCd==67 && isBpCanWts){
								e.column.editor.readonly = true;
							}
                            if(e.record.feeTypCd==30 && isBpCanWts){
                                e.column.editor.readonly = true;
                            }

        				}
        				if(isBp&&isBp=='1'){
            				if(e.record.feeTypCd==67 && isBpCanWts){
                                e.column.editor.readonly = true;
							}


            			}
        				if(isBp&&isBp=='3'){
            				if(e.record.feeTypCd==30 && isBpCanWts){
                                e.column.editor.readonly = true;
							}
            			}
        			}
        		}

            //事业部新车业务供应商返利和销售返利不可编辑
            saleAndSupplierRebate(e);
			// 重卡事业部 城配/传统 我司 报价方案名为重卡灵活报价方案 费用类型为租金补助服务费 不可编辑
			rentAllowanceServiceNotEditor(e);
        },
        onAfterEdit: function (e) {
          var calBaseCd = e.record.calBaseCd;
          var isFixedAmt = e.record.isFixedAmt;
          var  feeTypCd = e.record.feeTypCd;
        	if(e.column.name =="feePct"){
        		var pct = e.record.feePct;
          		 var minPct = e.record.feePctMin;
            	 var maxPct = e.record.feePctMax;
            	 if(pct&&minPct&&maxPct&&pct!="undefined"&&minPct!="undefined"&&maxPct!="undefined"){
	             	 if(pct<minPct||pct>maxPct){
	             		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "请输入"+minPct+"~"+maxPct+"之间的数值！"});
	             		  e.value = e.lastValue;
	             		 feeGrid.updateRow(e.record,{
	              			feePct: ''
	                      });
	             	 }else{
	             		 pct = Number(pct);
	            		 if(typeof pct =='number'&&isFixedAmt!=1){
	            			  var amt = getAmt(e.value,calBaseCd,feeTypCd,isFixedAmt);
	 		             	 feeGrid.updateCell('feePct', e.value, e.record);
	 		             	 feeGrid.updateCell('feeAmt', amt, e.record);
	 		              }
	             	 }
            	 }else{
            		 if(minPct==0||minPct==0){
            	      	 if(pct<minPct||pct>maxPct){
   	             		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "请输入"+minPct+"~"+maxPct+"之间的数值！"});
   	             		  e.value = e.lastValue;
   	             		 feeGrid.updateRow(e.record,{
   	              			feePct: ''
   	                      });
   	             	 }else{
   	             	 pct = Number(pct);
            		 if(typeof pct =='number'&&isFixedAmt!=1){
            			  var amt = getAmt(e.value,calBaseCd,feeTypCd,isFixedAmt);
 		             	 feeGrid.updateCell('feePct', e.value, e.record);
 		             	 feeGrid.updateCell('feeAmt', amt, e.record);
 		             	 }
   	             	 }
              }else{
            		 pct = Number(pct);
            		 if(typeof pct =='number'&&isFixedAmt!=1){
            			  var amt = getAmt(e.value,calBaseCd,feeTypCd,isFixedAmt);
 		             	 feeGrid.updateCell('feePct', e.value, e.record);
 		             	 feeGrid.updateCell('feeAmt', amt, e.record);
 		             	 }
            		 }

            		 }
		//重卡除厂商业务判断咨询费(供返)+咨询费(销返)是否小于等于供应商返利
                if(((buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK)||buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZC)&&!((prjTypCd==ProjectConstant.PRJ_TYP_CD_CPYW && isSplMfr == '1')||(prjTypCd==ProjectConstant.PRJ_TYP_CD_CTYW && isSplMfr == '1'))){
            		 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_71||feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_72||feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_05){
            			  var rows = feeGrid.rows;
            			  var splBack=0;//供应商返利 
            			  var consltSplBack=0;//咨询费供应商返利
            			  var consltSalBak =0;//咨询费销售返利
            			  if(rows){
	         				 for (var i = 0; i < rows.length; i++) {
	         				  			var feeTypCd = rows[i].feeTypCd;
	         					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_05){
	         						splBack = (parseFloat(rows[i].feeAmt)).toFixed(2);
	         			  			}
	         					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_71){
	         						consltSplBack = (parseFloat(rows[i].feeAmt)).toFixed(2);
		         			  		}
	         					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_72){
	         						consltSalBak = (parseFloat(rows[i].feeAmt)).toFixed(2);
		         			  		}
	         				 }
	         				 if(parseFloat(consltSplBack)+parseFloat(consltSalBak)>parseFloat(splBack)){
	         					UIUtils.alertWarning("咨询费(供返)与咨询费(销返)之和不能大于咨询费2金额！");
	      	             		//  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "咨询费(供返)与咨询费(销返)之和不能大于咨询费2金额！"});
	         				 }
            			  }
            		 	}
            	 }
 
            	 
        	}

     /*
        	if(e.column.name =="feeTypCd"){
        	   	var type = e.record.feeTypCd;//获取值
            		//判断添加时是否重复添加
            		 var grid = $("#ligergrid_fee").ligerGetGridManager();
                     var data = grid.getData();
                     var  num = 0;
            		for(var i=0;i<data.length;i++){
            			if(data[i].feeTypCd==type){
                   		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "该费用选项已经存在！",});
            				break;
            			}
            		}
       	}  */

     	//如果浦发业务购置税=发票金额*11.3
		if(e.record.feeTypCd == ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_63){
			if(ProjectConstant.PRJ_INS_CODE_PSD == insCode){
				var rows = feeGrid.rows;
				for (var j = 0; j < rows.length; j++) {
					if(rows[j].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_30){
						var amt  =(Math.ceil((e.record.feeAmt*100/11.3))/100).toFixed(2);
						feeGrid.updateRow(rows[j],{
							feeAmt: amt,
						});
					}
				}
			}
		}

       	//如果为固定金额，设置比例字段为只读
    	if(e.column.name =="isFixedAmt"){
   		 var isFixedAmt = e.record.isFixedAmt;
   		 var calBaseCd = e.record.calBaseCd;
   		 if(isFixedAmt==CommonConstant.C_YN_Y){
   		 	e.record.calBaseCd=' ';
   			e.record.calBaseCdNm = ' ';
   			e.record.feePct='  ';
   		 feeGrid.updateCell('feePct', '', e.record);
   		 if(e.record.feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_PURCHASE){
   			 feeGrid.updateCell('feeAmt', totalRsrvPcStr, e.record);
   		 }else if(e.record.feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_62){
   		     if(isSplMfr == '1'&&calId){
                 feeGrid.updateCell('feeAmt', e.record.isFixedAmt, e.record);
             }else{
                 var amt = (parseFloat(e.record.isFixedAmt*prdNum)).toFixed(2);
                 feeGrid.updateCell('feeAmt', amt, e.record);
             }
   		 }else{
   		 feeGrid.updateCell('feeAmt', 0, e.record);
   		 }
   		 feeGrid.updateCell('calBaseCd', ' ', e.record);
   		 }

   	}
         	if(e.column.name =="calBaseCd"){
        		 var feeTypCd = e.record.feeTypCd;
        		 var calBaseCd = e.record.calBaseCd;
        		 var isFixedAmt = e.record.isFixedAmt;
        		if(feeTypCd=="01"&&calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
        			//首期款
        			top.$.ligerDialog.SQalert({SQ_type: "warning",content: "首期款的计算基数不能为融资额！"});
        		}
        		 var feeAmt = e.record.calBaseCd;
        		 var feePct = e.record.feePct;
        	      var  feeTypCd = e.record.feeTypCd;
				if(feePct){
					if(feePct>0){
						  var amt = getAmt(feePct,calBaseCd,feeTypCd,isFixedAmt);
			             	 feeGrid.updateCell('feeAmt', amt, e.record);
					}

				}

        	}
         	if(e.column.name =="feeAmt"){
        		var feeAmt = e.value;
         		 var minPct = e.record.feePctMin;
           		 var maxPct = e.record.feePctMax;
            	 var isFixedAmt = e.record.isFixedAmt;
                 var  feeTypCd = e.record.feeTypCd;
            	 var feePct = getPct(feeAmt,calBaseCd,feeTypCd,isFixedAmt);
            	 var maxPct = e.feePctMax;
            	 if(feePct&&minPct&&maxPct&&feePct!="undefined"&&minPct!="undefined"&&maxPct!="undefined"){
	             	 if(feePct<minPct||feePct>maxPct){
	             		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "比例不在规定的范围内，范围：["+minPct+"~"+maxPct+"]请调整！"});
	             		 e.value = e.lastValue;
	             		 feeGrid.updateRow(e.record,{
	             			feeAmt: e.value
	                      });
	             	 }
             	 }else{
             		 if(typeof feeAmt =='number'&&isFixedAmt!=1){
             		    feeGrid.updateCell('feePct', feePct, e.record);
             		 }
                     if(typeof feeAmt =='number'&&isFixedAmt == 1){
                         setContFinalamt(feeAmt,calBaseCd,feeTypCd,isFixedAmt,e.record.cntWayCd);
                     }
             	 }

            	//重卡除厂商业务判断咨询费(供返)+咨询费(销返)是否小于等于供应商返利
                if(((buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK)||buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZC)&&!((prjTypCd==ProjectConstant.PRJ_TYP_CD_CPYW && isSplMfr == '1')||(prjTypCd==ProjectConstant.PRJ_TYP_CD_CTYW && isSplMfr == '1'))){
            		 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_71||feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_72||feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_05){
            			  var rows = feeGrid.rows;
            			  var splBack=0;//供应商返利 
            			  var consltSplBack=0;//咨询费供应商返利
            			  var consltSalBak =0;//咨询费销售返利
            			  if(rows){
	         				 for (var i = 0; i < rows.length; i++) {
	         				  			var feeTypCd = rows[i].feeTypCd;
	         					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_05){
	         						splBack = (parseFloat(rows[i].feeAmt)).toFixed(2);
	         			  			}
	         					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_71){
	         						consltSplBack = (parseFloat(rows[i].feeAmt)).toFixed(2);
		         			  		}
	         					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_72){
	         						consltSalBak = (parseFloat(rows[i].feeAmt)).toFixed(2);
		         			  		}
	         				 }
	         				 if(parseFloat(consltSplBack)+parseFloat(consltSalBak)>parseFloat(splBack)){
	      	             		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "咨询费(供返)与咨询费(销返)之和不能大于咨询费2金额！"});
	         				 }
            			  }
            		 	}
            	 }


       	}
        },
        onBeforeSubmitEdit: function (e) {//重新赋值,要不然选中后离开会把key显示在前端
            if (e.selected && e.column.columnname == "feeTypCdNm") {
                e.record.feeTypCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "calBaseCdNm") {
                e.record.calBaseCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "cntWayCdNm") {
                e.record.cntWayCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "isFixedAmtNm") {
                e.record.isFixedAmtId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if(e.column.columnname == "isFixedAmt" && e.selected) e.record.editable = e.selected.key;
        },
		onsuccess: function(data){
			var rowdata = data.rows;
			for(index in rowdata){
				if(rowdata[index].isRoute && rowdata[index].isRoute == CommonConstant.C_YN_Y){
					if(rowdata[index].feeTypCd == ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_02){
						feeGrid.updateCell('feeAmt',rowdata[index].fixedAmt,rowdata[index]);
					}
				}
			}
		},
        usePager: false,
        root: 'rows',
        record: 'total',
        hideLoadButton: true,
        width: '100%',
        height: 300,
        heightDiff: -2,
        enabledEdit: editFlag,
        isScroll: false,
        checkbox: editFlag,
        rownumbers: true,
        allowUnSelectRow: true,
        alternatingRow: false,
        enabledSort: false
    });
	}

/**
 * 事业部新车业务供应商返利和销售返利不可编辑
 */
function saleAndSupplierRebate(e) {

    if (buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK && (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW || prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)) {
        //供应商返利
        if(e.record.feeTypCd== ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_08 && e.record.feeTypCdNm == '供应商返利'){
            e.column.editor.readonly = true;
        }
        //销售返利
        if(e.record.feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_49 && e.record.feeTypCdNm == '销售返利'){
            e.column.editor.readonly = true;
        }
    }
}
/*
 * 重卡事业部 城配/传统 我司 报价方案名字为重卡灵活报价方案
 */
function rentAllowanceServiceNotEditor(e) {
	if (buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK && (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW || prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)) {
		if (insCode == '' || insCode == null) {
			// 费用项类型是 租金补助费用
			if(e.record.feeTypCd == ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_116){
				e.column.editor.readonly = true;
			}
		}
	}
}
	
function initCalculateGrid(flag){
    var form = liger.get("formSet1");
	var data = form.getData();
	var lsPd = $("#lsPd").val();
	//判断是否满足阶梯还款条件
	var payTypCd = $("#payWayCd").val();
    var isBp = $("#isBp").val();
    var payTax;//购置税
    var insurance;//保险费
	var rsrvPcValue;//留购价
	var invoiceValue;

	var rows = feeGrid.rows;
	if (rows) {
		for (var i = 0; i < rows.length; i++) {
			var feeTypCd = rows[i].feeTypCd;
			if (feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_30) {
				payTax = rows[i].feeAmt;
			}
			if (feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_67) {
				insurance = rows[i].feeAmt;
			}
			if (feeTypCd==ProjectConstant.PRJ_FEE_TYP_PURCHASE) {
				rsrvPcValue = rows[i].feeAmt;
			}
		}
	}
	/**
	 *  REQ-14544 平安银行是否包牌校验逻辑调整
	 *  是否包牌字段选否或者包购置税时，【购置税】、【保险费】字段可编辑，保存报价方案时，
	 *  【购置税】、【保险费】字段均必须>0；否则提示“平安银行资管业务【购置税】、【保险费】必填”
	 */
	if (ProjectConstant.PRJ_INS_CODE_PABANK == insCode) {
		if (payTax <= 0.00 || insurance <= 0.00 || payTax == '' || insurance == '') {
			top.$.ligerDialog.SQalert({content: "平安银行资管业务【购置税】、【保险费】必填", SQ_type: "warning"});
			return false;
		}
	} else {
		if ((payTax <= 0.00 || payTax == '') &&
				(ProjectConstant.PRJ_INS_CODE_SHNSBANK == insCode || ProjectConstant.PRJ_INS_CODE_PSD == insCode)) {
			/**
			 * 上海农商银行,浦发
			 * 购置税不能小于等于0
			 */
			top.$.ligerDialog.SQalert({content: "购置税小于等于0，请重新填写！", SQ_type: "warning"});
			return false;
		}
		if ((insurance <= 0.00 || insurance == '')
				&& (ProjectConstant.PRJ_INS_CODE_SHNSBANK == insCode)) {
			/**
			 *  上海农商银行
			 *  保险费不能小于等于0
			 */
			top.$.ligerDialog.SQalert({content: "保险费小于等于0，请重新填写！", SQ_type: "warning"});
			return false;
		}
		if (rsrvPcValue != 0.00 && rsrvPcValue == '' && ProjectConstant.PRJ_INS_CODE_ZYFL == insCode) {
			/**
			 *  浙银机构
			 *  留购价必须为0
			 */
			top.$.ligerDialog.SQalert({content: "留购价必须为0，请修改", SQ_type: "warning"});
			return false;
		}
		/**
		 * 根据是否包牌对购置税和保险费进行通用判断
		 */
		if (isBp == '1') {
			// 判断 是否包牌价是包购置税时需填写购置税
			if (payTax <= 0.00 || payTax == '') {
				top.$.ligerDialog.SQalert({content: "请填写购置税", SQ_type: "warning"});
				return false;
			}
		} else if (isBp == '2') {
			// 判断 是否包牌价是包购置税和保险时需填写购置税和保险
			if (payTax <= 0.00 || insurance <= 0.00 || payTax == '' || insurance == '') {
				top.$.ligerDialog.SQalert({content: "请填写购置税；请填写保险费", SQ_type: "warning"});
				return false;
			}
		} else if (isBp == '3') {
			// 判断 是否包牌价是保险时需填写保险
			if (insurance <= 0.00 || insurance == '') {
				top.$.ligerDialog.SQalert({content: "请填写保险费", SQ_type: "warning"});
				return false;
			}
		}
	}

	// 传统/城配项目，我司首期款比例不能小于10%
	if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK && CommonConstant.C_YN_N == isInsBiz
			&& (prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW || prjTypCd == ProjectConstant.CODE_PRJ_TYP_CD_CPYW)){
		var rows = feeGrid.rows;
		for (var i = 0; i < rows.length; i++) {
			if(rows[i].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_01 &&  rows[i].feePct < 10){
				top.$.ligerDialog.SQalert({content: "首期比例不能小于10%", SQ_type: "warning"});
				return false ;
			}
		}
	}

	//重卡除厂商业务判断咨询费(供返)+咨询费(销返)是否小于等于供应商返利
    if(((buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK)||buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZC)&&!((prjTypCd==ProjectConstant.PRJ_TYP_CD_CPYW && isSplMfr == '1')||(prjTypCd==ProjectConstant.PRJ_TYP_CD_CTYW && isSplMfr == '1'))){
 			  var rows = feeGrid.rows;
 			  var splBack=0;//供应商返利 
 			  var consltSplBack=0;//咨询费供应商返利
 			  var consltSalBak =0;//咨询费销售返利
 			  if(rows){
  				 for (var i = 0; i < rows.length; i++) {
  				  			var feeTypCd = rows[i].feeTypCd;
  					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_05){
  						splBack = (parseFloat(rows[i].feeAmt)).toFixed(2);
  			  			}
  					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_71){
  						consltSplBack = (parseFloat(rows[i].feeAmt)).toFixed(2);
      			  		}
  					 if(feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_72){
  						consltSalBak = (parseFloat(rows[i].feeAmt)).toFixed(2);
      			  		}
  				 }
  				 if(parseFloat(consltSplBack)+parseFloat(consltSalBak)>parseFloat(splBack)){
  					UIUtils.alertWarningHold1("咨询费(供返)与咨询费(销返)之和不能大于咨询费2金额！");
  					return;
	             		//  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "咨询费(供返)与咨询费(销返)之和不能大于咨询费2金额！"});
  				 }
 			  }
 	 }

	  if(payTypCd&&payTypCd==ProjectConstant.CODE_PAY_QUAT_MULTI_STEP){
			$.ajax({
				type: 'get',
				dataType:'json',
				data:{"payPd":lsPd,
					"prjId":prjId},
				url: '<%=path%>/project/prjquatprps/checkMultiStepStatus.do',
				success:function(msg){
					 if(msg.success!=1){
						 UIUtils.alertWarningHold1("不可选择该支付方式，请选择其他支付方式");
						// $.ligerDialog.SQalert({content: "不可选择该支付方式，请选择其他支付方式", SQ_type: "warring"});
							return;
					 }else{
						    var detailListData = feeGrid.getData();
							    var id = $("#prpsId").val();
						           data["id"]= id;
						           data["prjId"] = prjId;
						           data["prpsCfgId"]=$("#prpsCfgId").val();
						           data["lsPdUntCd"]=$("#lsPdUntCd").val();
						           data["payWayCd"]=$("#payWayCd").val();
						           data["lsCalWayCd"]=$("#lsCalWayCd").val();
						           data["intRateWayCd"]=$("#intRateWayCd").val();
						           data["dpstHdlWayCd"]=$("#dpstHdlWayCd").val();
						           data["expHdlWayCd"]=$("#expHdlWayCd").val();
						           data["noPayWayCd"]=$("#noPayWayCd").val();
						       	   data["feeDetailList"] = JSON.stringify(detailListData);
						       	   data["isModify"] = isModify;
						       	   data["prpsTypCd"]=$("#prpsTypCd").val();
						       	   data["actLsAmt"]=$("#actLsAmt").val();
						       	var payWay = $("#payWayCd").val();
						       	var calculateGridData ;
						     	if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
						     		flag= true;
						     	}
						       	if(isModify){
							       	if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
							          calculateGridData = calculateGrid.getData();
							          for ( var i=0; i<calculateGridData.length;i++) {
							        	  var obj = calculateGridData[i];
										if(!obj.isModify){
											obj.isModify = CommonConstant.C_YN_N;
										}
									  }
							          data["payList"] = JSON.stringify(calculateGridData);
							       	}
						       	}
						$.ajax({
							type: 'post',
							dataType:'json',
							data:data,
							url: '<%=path%>/project/prjquatprps/calculate.do',
                            beforeSend: function(){
                                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                            },
							success:function(msg){
								wait_dialog.close();
								 if(msg.success == 1){
									 prjQuatPrps = msg.data;
									 if(prjQuatPrps.isShowIns == CommonConstant.C_YN_Y){
										 $.ligerDialog.SQopen({
											 width: 800,
											 top: 100,
											 buttons: [
												 {
													 text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
														 $.ligerDialog.hide();
													 }
												 }
											 ],
											 title : '机构筛选结果',
											 target: $("#res_div")
										 });
										 isAllowNonIns = prjQuatPrps.isAllowNonIns;
										 if(isAllowNonIns == CommonConstant.C_YN_Y){
											 $("#isAllowNonIns").html("特批标识：是");
										 }else{
											 $("#isAllowNonIns").html("特批标识：否");
										 }
										 if(prjQuatPrps.gctInsResList == null || !(prjQuatPrps.gctInsResList.length>0)){
											 $("#defaultText").show();
											 $("#defaultTip").hide();
										 }else{
											 $("#defaultText").hide();
											 $("#defaultTip").show();
										 }
										 ligerGrid_heguijigou.loadData({rows:prjQuatPrps.gctInsResList});
										 ligerGrid_heguijigouUn.loadData({rows:prjQuatPrps.ungctInsResList});
									 }else{
										 calculateData =  msg.data.prjQuatPrpsPaySchPage;
										 $("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
										 $("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
										 $("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
										 $("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
										 $("#actLsAmt").val(prjQuatPrps.actLsAmt);
										 $("#irrPct").val(prjQuatPrps.irrPct);
										 $("#irrPct2").val(null==prjQuatPrps.irrPct2?"":prjQuatPrps.irrPct2);
										 $("#cstIrr").val(null==prjQuatPrps.cstIrr?"":prjQuatPrps.cstIrr);
										 $("#tenThouCoef").val(null==prjQuatPrps.tenThouCoef?"":prjQuatPrps.tenThouCoef);

										 $("#eachEstRntAmt").val(prjQuatPrps.eachEstRntAmt);
										 if(!prjQuatPrps.checkResultDesc&&insCode){
											 $("#insMsgDiv").show();
											 $("#checkInfo").text("该方案无合适的机构！");
										 }
										 if(prjQuatPrps.checkResultDesc&&insCode){
											 $("#insMsgDiv").show();
											 $("#checkInfo").text(prjQuatPrps.checkResultDesc);
										 }
										 calculateGrid = $("#ligergrid_calculate").ligerGrid({
											 data: $.extend(true,{},calculateData),
											 columns: [
												 { display: '支付时间', name: 'payDt', render:renderDate, minWidth: 60 },
												 { display: '期次', name: 'payPd',minWidth: 140},
												 { display: '租金', name: 'rntAmt', minWidth: 140, type:'currency',render:renderAmt,
													 editor: {type: 'number',
														 precision:2,
														 toFix:true,
														 onToFix:function(){
															 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
														 }},
													 enabledSort:true},
												 { display: '本金', name: 'prinAmt', minWidth: 60, type:'currency',
													 render:renderAmt},
												 { display: '利息', name: 'intAmt', minWidth: 140, type:'currency',
													 render:renderAmt},
												 { display: '剩余本金', name: 'remPrinAmt', minWidth: 140, type:'currency',
													 render:renderAmt},
											 ],
											 onBeforeEdit: function (e) {
												 e.lastValue = e.value;
												 if(!e.record.isModify){
													 e.record.isModify= CommonConstant.C_YN_N;
												 }
											 },
											 onAfterEdit: function (e) {
												 var calBaseCd = e.record.calBaseCd;
												 if(e.column.name =="rntAmt"){
													 var value = e.value;
													 var lastValue = e.lastValue;
													 if(value!=lastValue&&lastValue){
														 isModify = true;
														 e.record.isModify= CommonConstant.C_YN_Y;
													 }
												 }

											 },
											 usePager: false,
											 pageSize:10,
											 root:'rows',
											 record:'total',
											 hideLoadButton : true,
											 width: '100%',
											 height:300,
											 heightDiff:-2,
											 //isScroll: false,
											 checkbox:true,
											 enabledEdit: flag,
											 rownumbers:true
										 });
										 if(prjQuatPrps.isHaveException==CommonConstant.C_YN_Y){
											 top.$.ligerDialog.SQalert({content: "修改后测算失败，请调整修改的租金值，从新测算！",SQ_type: "error"});
										 }
									 }
								 }else{
									 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
								 }
							}
						});

					 }
				  }
				});
	  }else{
		   var detailListData = feeGrid.getData();
		    var id = $("#prpsId").val();
	           data["id"]= id;
	           data["prjId"] = prjId;
	           data["lsPdUntCd"]=$("#lsPdUntCd").val();
	           data["payWayCd"]=$("#payWayCd").val();
	           data["lsCalWayCd"]=$("#lsCalWayCd").val();
	           data["intRateWayCd"]=$("#intRateWayCd").val();
	           data["dpstHdlWayCd"]=$("#dpstHdlWayCd").val();
	           data["expHdlWayCd"]=$("#expHdlWayCd").val();
	           data["noPayWayCd"]=$("#noPayWayCd").val();
	           data["prpsCfgId"]=$("#prpsCfgId").val();
	       	   data["feeDetailList"] = JSON.stringify(detailListData);
	       	   data["isModify"] = isModify;
	       	   data["prpsTypCd"]=$("#prpsTypCd").val();
	       	   data["actLsAmt"]=$("#actLsAmt").val();
	       	var payWay = $("#payWayCd").val();
	       	var calculateGridData ;
	     	if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
	     		flag= true;
	     	}
	       	if(isModify){
		       	if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
		          calculateGridData = calculateGrid.getData();
		          for ( var i=0; i<calculateGridData.length;i++) {
		        	  var obj = calculateGridData[i];
					if(!obj.isModify){
						obj.isModify = CommonConstant.C_YN_N;
					}
				  }
		          data["payList"] = JSON.stringify(calculateGridData);
		       	}
	       	}
	$.ajax({
		type: 'post',
		dataType:'json',
		data:data,
		url: '<%=path%>/project/prjquatprps/calculate.do',
        beforeSend: function(){
            wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
        },
		success:function(msg){
			 wait_dialog.close();
			 if(msg.success == 1){
				 prjQuatPrps = msg.data;
				 if(prjQuatPrps.isShowIns == CommonConstant.C_YN_Y){
					 $.ligerDialog.SQopen({
						 width: 800,
						 top: 100,
						 buttons: [
							 {
								 text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
									 $.ligerDialog.hide();
								 }
							 }
						 ],
						 title : '机构筛选结果',
						 target: $("#res_div")
					 });
					 isAllowNonIns = prjQuatPrps.isAllowNonIns;
					 if(isAllowNonIns == CommonConstant.C_YN_Y){
						 $("#isAllowNonIns").html("特批标识：是");
					 }else{
						 $("#isAllowNonIns").html("特批标识：否");
					 }
					 if(prjQuatPrps.gctInsResList == null || !(prjQuatPrps.gctInsResList.length>0)){
						 $("#defaultText").show();
						 $("#defaultTip").hide();
					 }else{
						 $("#defaultText").hide();
						 $("#defaultTip").show();
					 }
					 ligerGrid_heguijigou.loadData({rows:prjQuatPrps.gctInsResList});
					 ligerGrid_heguijigouUn.loadData({rows:prjQuatPrps.ungctInsResList});
				 }else{
					 calculateData =  msg.data.prjQuatPrpsPaySchPage;
					 $("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
					 $("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
					 $("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
					 $("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
					 $("#actLsAmt").val(prjQuatPrps.actLsAmt);
					 if(prjQuatPrps.smallLoanAmt){
                         $("#smallLoanAmt").parent().parent().parent().show();
                         $("#isLowDownPayment_txt").val($("#isLowDownPayment option[value=" + prjQuatPrps.isLowDownPayment +"]").text());
                         $("#isLowDownPayment_txt").show().parent().parent().parent().parent().show();
                         $("#smallLoanAmt").val(prjQuatPrps.smallLoanAmt);
                     }else{
                         $("#smallLoanAmt").val(prjQuatPrps.smallLoanAmt);
                         $("#smallLoanAmt").parent().parent().parent().hide();
                         $("#isLowDownPayment_txt").val("--请选择--");
                         $("#isLowDownPayment_txt").hide().parent().parent().parent().parent().hide();
					 }
					 $("#irrPct").val(prjQuatPrps.irrPct);
					 $("#irrPct2").val(null==prjQuatPrps.irrPct2?"":prjQuatPrps.irrPct2);
					 $("#tenThouCoef").val(null==prjQuatPrps.tenThouCoef?"":prjQuatPrps.tenThouCoef);
					 $("#eachEstRntAmt").val(prjQuatPrps.eachEstRntAmt);
					 if(!prjQuatPrps.checkResultDesc&&insCode){
						 $("#insMsgDiv").show();
						 $("#checkInfo").text("该方案无合适的机构！");
					 }
					 if(prjQuatPrps.checkResultDesc&&insCode){
						 $("#insMsgDiv").show();
						 $("#checkInfo").text(prjQuatPrps.checkResultDesc);
					 }
					 if(prjTypCd==ProjectConstant.PRJ_TYP_CD_CDDYWYQ){
						 $("#annIntRatePct").val(null==prjQuatPrps.annIntRatePct?"":prjQuatPrps.annIntRatePct);
					 }
					 // 测算回写费用项金额  TODO 测算 费用项 回写金额 浦发
					 var detailListData = msg.data.prjQuatPrpsFeelist;
					 var rows = feeGrid.rows;
					 for (var i = 0; i < rows.length; i++) {
						 var feeTypCd = rows[i].feeTypCd;
						 for(var j = 0,len = detailListData.length; j < len; j++){
							 if(detailListData[j].feeTypCd == feeTypCd){
								 feeGrid.updateRow(rows[i],{
									 feeAmt:detailListData[j].feeAmt,
									 feePct:detailListData[j].feePct
								 });
							 }
						 }

					 }
					 calculateGrid = $("#ligergrid_calculate").ligerGrid({
						 data: $.extend(true,{},calculateData),
						 columns: [
							 { display: '支付时间', name: 'payDt', render:renderDate, minWidth: 60 },
							 { display: '期次', name: 'payPd',minWidth: 140},
							 { display: '租金', name: 'rntAmt', minWidth: 140, type:'currency',render:renderAmt,
								 editor: {type: 'number',
									 precision:2,
									 toFix:true,
									 onToFix:function(){
										 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
									 }},
								 enabledSort:true},
							 { display: '本金', name: 'prinAmt', minWidth: 60, type:'currency',
								 render:renderAmt},
							 { display: '利息', name: 'intAmt', minWidth: 140, type:'currency',
								 render:renderAmt},
							 { display: '剩余本金', name: 'remPrinAmt', minWidth: 140, type:'currency',
								 render:renderAmt},
						 ],
						 onBeforeEdit: function (e) {
							 e.lastValue = e.value;
							 if(!e.record.isModify){
								 e.record.isModify= CommonConstant.C_YN_N;
							 }
						 },
						 onAfterEdit: function (e) {
							 var calBaseCd = e.record.calBaseCd;
							 if(e.column.name =="rntAmt"){
								 var value = e.value;
								 var lastValue = e.lastValue;
								 if(value!=lastValue&&lastValue){
									 isModify = true;
									 e.record.isModify= CommonConstant.C_YN_Y;
								 }
							 }

						 },
						 usePager: false,
						 pageSize:10,
						 root:'rows',
						 record:'total',
						 hideLoadButton : true,
						 width: '100%',
						 height:300,
						 heightDiff:-2,
						 //isScroll: false,
						 checkbox:true,
						 enabledEdit: flag,
						 rownumbers:true
					 });
					 if(prjQuatPrps.isHaveException==CommonConstant.C_YN_Y){
						 top.$.ligerDialog.SQalert({content: "修改后测算失败，请调整修改的租金值，从新测算！",SQ_type: "error"});
					 }
				 }
			 }else{
				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			 }
		}
	});

	  }




}
function setContFinalamt(feeAmt,calBaseCd,feeTypCd,isFixedAmt,cntWayCd){
    if(feeAmt&&isFixedAmt==1){
        var contAmt = parseFloat($("#totLsItmAmt").val())
        var rows = feeGrid.rows;
        for (var i = 0; i < rows.length; i++) {
            var feeTypCd2 = rows[i].feeTypCd;
            var cntWayCd = rows[i].cntWayCd;
            if(cntWayCd == "4"){
                contAmt += parseFloat(rows[i].feeAmt);
            }
        }
        $("#contAmt").val(contAmt);
        var firstAmt =0;
        for (var i = 0; i < rows.length; i++) {
            var firstAmtFeeTypCd = rows[i].feeTypCd;
            if(firstAmtFeeTypCd=='01'){
                var detailFct = parseFloat(rows[i].feePct)/100;
                var calCd = rows[i].calBaseCd;
                if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
                    firstAmt  =(detailFct*contAmt).toFixed(2);
                }
                if(calCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
                    firstAmt  =(detailFct*totalAmt).toFixed(2);
                }
                feeGrid.updateRow(rows[i],{
                    feeAmt: firstAmt,
                });
            }
        }
        var finaAmt = contAmt - firstAmt;
        $("#actLsAmt").val(finaAmt);
        for (var j = 0; j < rows.length; j++) {
            if(rows[j].calBaseCd==ProjectConstant.CAL_BASE_FINANCING&&rows[j].isFixedAmt!=1) {
                var amt  =(rows[j].feePct/100*finaAmt).toFixed(2);
                feeGrid.updateRow(rows[j],{
                    feeAmt: amt,
                });
            }

        }
    }

}

function getPct(feeAmt,calBaseCd,feeTypCd,isFixedAmt){
	var feeFct = '';
	if(feeAmt&&isFixedAmt!=1){
	//计算费用值
	if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
		var firstAmt =0;
		//根据融资额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
		  var rows = feeGrid.rows;
			 for (var i = 0; i < rows.length; i++) {
			  			var feeTypCd = rows[i].feeTypCd;
				 if(feeTypCd=="01"){
	        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
			  			var calCd = rows[i].calBaseCd;
			  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
			  			firstAmt  =(detailFct*contAmt).toFixed(2);
			  			}
			  			if(calCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
			  				firstAmt  =(detailFct*totalAmt).toFixed(2);
			  			}
		  			}
			 }
			var financ = contAmt-firstAmt;
		feeFct =(parseFloat(feeAmt)/financ*100).toFixed(feeScale);
	}

	if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			//根据合同额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		feeFct =(parseFloat(feeAmt)/contAmt*100).toFixed(feeScale);
		}
	//设备款
	if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
		//根据合同额计算
	var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
	feeFct =(parseFloat(feeAmt)/totalAmt*100).toFixed(feeScale);
	}
	//如果更改首期款，融资额费用项为不可修改，按比例重新计算计入融资额的费用项，如果融资额费用项可以修改，清空费用项，修改实际融资额值
	if(feeTypCd=='01'){
		var firstAmt = 0;
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
		 var detailFct = parseFloat(feeFct)/100;
			if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			firstAmt  =(detailFct*contAmt).toFixed(2);
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				firstAmt  =(detailFct*totalAmt).toFixed(2);
			}
		//融资额
		var finaAmt = 0;
		if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			finaAmt  =contAmt-firstAmt;
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				finaAmt  =totalAmt-firstAmt;
			}
			//设置实际融资额值
	//		if(finaAmt>0){
				//
				$("#actLsAmt").val(finaAmt);
				//重新计算融资额信息
				 var rows = feeGrid.rows;
					 for (var j = 0; j < rows.length; j++) {

						if(rows[j].calBaseCd==ProjectConstant.CAL_BASE_FINANCING&&rows[j].isFixedAmt!=1){
							if(rows[j].isAllowChg==1){

								feeGrid.updateRow(rows[j],{
				                    feeAmt:0,
				                    feePct:0
				                });

							}else{
								var 	amt  =(rows[j].feePct/100*finaAmt).toFixed(2);
								feeGrid.updateRow(rows[j],{
				                    feeAmt: amt,
				                });


							}
						}

					 }

	//		}

	}




}
	return Number(feeFct);
}

/**
 * 重卡事业部 传统/城配 我司报价方案名称为重卡灵活报价方案，显示，
 */
function rentAllowanceServiceIsShow(prjQuatPrps) {
	if (buOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK && (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW || prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)) {

		// 我司且报价方案名称为重卡灵活报价方案，显示捆绑租金补助服务下拉框 或者 是资管项目
		if (((insCode == '' || insCode == null) && prjQuatPrps.prpsCfgNm == '重卡灵活报价方案') || (insCode != '' && insCode != null)) {
			// 显示
			$("#rentAllowanceServiceDiv").show();

			var selected =  prjQuatPrps.rentAllowanceService;
			// 将查询出来的数据赋值
			var selectid= $("#rentAllowanceService").ligerGetComboBoxManager();
			selectid.setValue(selected);
			selectid.setText(selected == 1 ? '是' : '否');
			// 查看的标志 是detailFlag
			if (detailFlag == 'true') {
				liger.get("rentAllowanceService").setDisabled(true);
			} else {
				var prdListArray = JSON.parse(prdList);
				/*
                 * 判断下项目车型校验，该项目下全是挂车，下拉选项置灰不可操作，初始状态是否
                */
				// 用于标记挂车的数量
				var j = 0;
				for(var i = 0;i < prdListArray.length;i ++) {
					var prdTypCd = prdListArray[i].prdTypCd;
					if (prdTypCd == ProjectConstant.PRD_TYP_CD_9) {
						j ++;
					}
				}

				if (j == prdListArray.length) {
					liger.get("rentAllowanceService").setDisabled(true);
				}

			}
		}
	}
}


function  getAmt(feePct,calBaseCd,feeTypCd,isFixedAmt){
	 var feeAmt = 0;
		 //如果存在比例值计算金额值
	if(feePct&&isFixedAmt!=1){
		feePct =parseFloat(feePct).toFixed(feeScale)
		//计算费用值
		if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
			//根据融资额计算
			var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
			var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
			  var rows = feeGrid.rows;
			var firstAmt =0;
				 for (var i = 0; i < rows.length; i++) {
				  			var feeTypCd = rows[i].feeTypCd;
					 if(feeTypCd=="01"){
		        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
				  			var calCd = rows[i].calBaseCd;
				  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
				  			firstAmt  =(detailFct*contAmt).toFixed(2);
				  			}
				  			if(calCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				  				firstAmt  =(detailFct*totalAmt).toFixed(2);
				  			}
			  			}
				 }
				var financ = contAmt-firstAmt;
			//根据设备款计算
			feeAmt =(parseFloat(feePct)/100*financ).toFixed(2);
		}

	if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			//根据合同额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		feeAmt =(parseFloat(feePct)/100*contAmt).toFixed(2);
		}

	//设备款
	if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
		//根据合同额计算
	var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
	feeAmt =(parseFloat(feePct)/100*totalAmt).toFixed(2);
	}

	//如果更改首期款，融资额费用项为不可修改，按比例重新计算计入融资额的费用项，如果融资额费用项可以修改，清空费用项，修改实际融资额值
	if(feeTypCd=='01'){
		//根据融资额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
		var firstAmt = 0;
		 var detailFct = parseFloat(feePct)/100;
			if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			firstAmt  =(detailFct*contAmt).toFixed(2);
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				firstAmt  =(detailFct*totalAmt).toFixed(2);
			}
		//融资额
		var finaAmt = 0;
		if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			finaAmt  =contAmt-firstAmt;
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				finaAmt  =totalAmt-firstAmt;
			}
			//设置实际融资额值
		//	if(finaAmt>0){
				//
				$("#actLsAmt").val(finaAmt);
				//重新计算融资额信息
				 var rows = feeGrid.rows;
					 for (var j = 0; j < rows.length; j++) {

						if(rows[j].calBaseCd==ProjectConstant.CAL_BASE_FINANCING&&rows[j].isFixedAmt!=1){
							if(rows[j].isAllowChg==1){

								feeGrid.updateRow(rows[j],{
				                    feeAmt: 0,
				                    feePct:0
				                });

							}else{
								var 	amt  =(rows[j].feePct/100*finaAmt).toFixed(2);
								feeGrid.updateRow(rows[j],{
				                    feeAmt: amt,
				                });


							}
						}

					 }

		//	}

	}
	}



	return Number(feeAmt);
}
//查找年利率
function searchAnnIntRatePct(){
    if(!isSplMfr||(isSplMfr&&isSplMfr == '0')){
		if(searchAnnIntRatePctMark == CommonConstant.C_YN_Y){
			var params = {};
			params.quatId=$("#prpsCfgId").val();
			params.lsPd = $("#lsPd").val();
			params.lsPdUntCd = $("#lsPdUntCd").val();
			$.ajax({
				type: 'post',
				dataType:'json',
				data:params,
				url: '<%=path%>/project/prjquatprps/getQuatPrpsCfgAiByQuatId.do',
				success:function(msg){
					if(msg.success == 1){
						if(msg.data){
							annIntRatePct = parseFloat(msg.data.annIntRatePct).toFixed(annIntScale);
							var parcent =  null;
							if($("#intRateRsPct").val()!=''){
								parcent = (parseFloat(msg.data.annIntRatePct)*((1+parseFloat($("#intRateRsPct").val()).toFixed(floatScale))/100)).toFixed(annIntScale);
							}
							parcent =parseFloat(msg.data.annIntRatePct).toFixed(annIntScale);
							$("#annIntRatePct").val(parcent);
						}
					}else{
						if(annIntRatePct!=0){
							$("#annIntRatePct").val(annIntRatePct);
						}else{

						}
					}
				}
			});
			var prpsCfgNm = $("#prpsCfgNm").val();
			if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_QK && prpsCfgNm.indexOf("东风") != -1){
				var prpsCfgId = $("#prpsCfgId").val();
				var lsPd = $("#lsPd").val();
				var url= '<%=path%>/project/prjQuatPrpsCfgD/initListForQk.do?prjId='+prjId+'&&prpsCfgId='+prpsCfgId+'&&lsPd='+lsPd;
				var editFlag = true;
				if(detailFlag=="true"){
					editFlag = false;
				}
				prjQuatPrpsfeeGrid(url,editFlag,1);
			}
		}else {
			searchAnnIntRatePctMark = CommonConstant.C_YN_Y;
		}
        setRentPeriod();
    }

}
	function setRentPeriod(){
		//根据选择的租赁单位计算租赁周期
		var rentPeriod = '';
		var lsPd = $("#lsPd").val();
		var lsPdUntCd = $("#lsPdUntCd").val();
		if(lsPd!=''){
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_MONTH){
				rentPeriod = parseFloat(lsPd)*1;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_YEAR){
				rentPeriod = parseFloat(lsPd)*12;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_DOUBLE_MONTH){
				rentPeriod = parseFloat(lsPd)*2;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_SEASON){
				rentPeriod = parseFloat(lsPd)*3;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_HALF_YEAR){
				rentPeriod = parseFloat(lsPd)*6;
			}
		}
		//设置租赁周期
		$("#rentPeriod").text(rentPeriod);
	}
	//根据上浮利率修改年利率信息
	function changeAnnIntRatePct(){
		if($("#intRateRsPct").val()!=0&&annIntRatePct!=""){
		var   parcent = (parseFloat(annIntRatePct)*((1+(parseFloat($("#intRateRsPct").val()).toFixed(floatScale))/100))).toFixed(annIntScale);
		 $("#annIntRatePct").val(parcent);
		}
	}
	//修改设备额的时候修改根据设备额计算的比例金额
	function changeBaseTotLsltmAmt(sts){
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
		  var rows = feeGrid.rows;
		  if(!rows||rows.length==0||sts == 1){
			  if(feeGrid.data){
			  rows = feeGrid.data.rows;

			//首期款比例相等，计算融资额，不相等设置融资额大小比例相等的比例值
			var firstAmt =0;
		     for (var j = 0; j < rows.length; j++) {
		    	  var minPct = parseFloat(rows[j].feePctMin)/100;
          	  var maxPct = parseFloat(rows[j].feePctMax)/100;
      		  if(minPct==maxPct){
     			 if(rows[j].feeTypCd=="01"){
      	 		 var detailFct = minPct/100;
		  			var calCd = rows[j].calBaseCd;
		  			if(calCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
		  			firstAmt  =(detailFct*contAmt).toFixed(2);
		  			}
		  			break;
	  				}

      		  }
		     }

          for (var i = 0; i < rows.length; i++) {
        	  var detailFct = parseFloat(rows[i].feePct)/100;
		  			var calBaseCd = rows[i].calBaseCd;
        	  if(typeof detailFct =='number'){
	  			var amt =(detailFct*totalAmt).toFixed(2);
	  			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
	  				feeGrid.updateRow(rows[i],{
	                    feeAmt: amt
	                });
				}
        	  }else{
        		  if(rows[i].feePctMin!='NaN'&&rows[i].feePctMax!='NaN'&&rows[i].feePctMin!='undefined'&&rows[i].feePctMax!='undefined'
        			  &&rows[i].feePctMin!=null&&rows[i].feePctMax!=null){
        		  var minPct = parseFloat(rows[i].feePctMin)/100;
            	  var maxPct = parseFloat(rows[i].feePctMax)/100;
        		  if(minPct==maxPct){
      				var amt =(minPct*totalAmt).toFixed(2);
	      			  if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
			  				feeGrid.updateRow(rows[i],{
			                    feeAmt: amt,
			                    feePct:minPct*100
			                });
						}else{
						    //有首期款，计入方式为融资额，大小比例值相等，计算融资额
	  						if(firstAmt>=0&&calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
	  							$("#actLsAmt").val(finaAmt);
	  							var finalAmt = totalAmt-firstAmt;
	  							var amt =(minPct*finalAmt).toFixed(2);
	  							feeGrid.updateRow(rows[i],{
		  		                    feeAmt: amt,
		  		                    feePct:(minPct*100).toFixed(feeScale)
		  		                });

	  						}else{
	  						  if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
	  							feeGrid.updateRow(rows[i],{
		  		                    feePct:(minPct*100).toFixed(feeScale)
		  		                });
	  						  }

	  						  if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
		  							feeGrid.updateRow(rows[i],{
			  		                    feePct:(minPct*100).toFixed(feeScale),
			  		                  	feeAmt: 0,
			  		                });
	  						  }
	  						}

						}

      			  }else{
        			  // 比例不相同不计算，金额默认为0
        			  feeGrid.updateRow(rows[i],{
  		                    feeAmt: 0
  		                });
        		  }
        		  }else{
        			  var isFixedAmt = rows[i].isFixedAmt;
        			  var fixedAmt = rows[i].fixedAmt;
        			  if(typeof fixedAmt=='number'&&isFixedAmt==1){
        				  if(rows[i].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_PURCHASE){
        					  fixedAmt = totalRsrvPcStr;
        				  }
        				  if(rows[i].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_62){
                              if(isSplMfr == '1'&&calId){
                                  fixedAmt = rows[i].fixedAmt;
                              }else {
                                  var amt = (parseFloat(fixedAmt * prdNum)).toFixed(2);
                                  fixedAmt = amt;
                              }
        				  }

        				  feeGrid.updateRow(rows[i],{
  		                    feeAmt: fixedAmt
  		                });
        			  }
        		  }
        			//是固定值
      		  	//设置比例信息
        		/* 	if(rows[i].fixedAmt){
      		  		var amt =(parseFloat(rows[i].fixedAmt)).toFixed(2);
	      		  	var feePct = (amt/totalAmt*100).toFixed(feeScale);
	      		  		 if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
	      		  				feeGrid.updateRow(rows[i],{
	      		                    feeAmt: amt,
	      		                    feePct:feePct
	      		                });
	      					}
        			} */
          }

          };

			  }
		  }

	}
	//修改合同额的时候修改根据合同额计算的比例金额
	function changeBaseContAmt(sts){
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		  var rows = feeGrid.rows;
		  if(!rows||rows.length==0||sts==1){
			  if(feeGrid.data){
			  rows = feeGrid.data.rows;

		//首期款比例相等，计算融资额，不相等设置融资额大小比例相等的比例值
			var firstAmt =0;
		     for (var j = 0; j < rows.length; j++) {
		    	  var minPct = parseFloat(rows[j].feePctMin)/100;
            	  var maxPct = parseFloat(rows[j].feePctMax)/100;
        		  if(minPct==maxPct){

       			 if(rows[j].feeTypCd=="01"){
        	 		 var detailFct = minPct;
		  			var calCd = rows[j].calBaseCd;
		  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
		  			firstAmt  =(detailFct*contAmt).toFixed(2);
		  			}
		  			break;
	  				}

        		  }
		     }
          for (var i = 0; i < rows.length; i++) {
        	  var detailFct = (parseFloat(rows[i].feePct)/100).toFixed(feeScale);
		  			var calBaseCd = rows[i].calBaseCd;
        	  if(detailFct&&detailFct!='NaN'){
		  			var amt =(detailFct*contAmt).toFixed(2);
		  			if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
		  				feeGrid.updateRow(rows[i],{
		                    feeAmt: amt
		                });
					}
        	  }else{
        		  if(rows[i].feePctMin!='NaN'&&rows[i].feePctMax!='NaN'&&rows[i].feePctMin!='undefined'&&rows[i].feePctMax!='undefined'
        			  &&rows[i].feePctMin!=null&&rows[i].feePctMax!=null){
	        		  var minPct = parseFloat(rows[i].feePctMin)/100;
	            	  var maxPct = parseFloat(rows[i].feePctMax)/100;
	            	  var baseCd = rows[i].calBaseCd;
	        		  if(minPct==maxPct){
	        				var amt =(minPct*contAmt).toFixed(2);
	        			  if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
	  		  				feeGrid.updateRow(rows[i],{
	  		                    feeAmt: amt,
	  		                    feePct:(minPct*100).toFixed(feeScale)
	  		                });
	  					}else{
  						     //有首期款，计入方式为融资额，大小比例值相等，计算融资额
	  						if(firstAmt>=0&&calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
	  							var finalAmt = contAmt-firstAmt;
	  							$("#actLsAmt").val(finalAmt);
	  							var amt =(minPct*finalAmt).toFixed(2);
	  							feeGrid.updateRow(rows[i],{
		  		                    feeAmt: amt,
		  		                    feePct:(minPct*100).toFixed(feeScale)
		  		                });

	  						}else{
	  						  if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
	  							feeGrid.updateRow(rows[i],{
		  		                    feePct:(minPct*100).toFixed(feeScale),
		  		                  feeAmt: amt,
		  		                });
	  						  }

	  						  if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
		  							feeGrid.updateRow(rows[i],{
			  		                    feePct:(minPct*100).toFixed(feeScale),
			  		                  	feeAmt: 0,
			  		                });
	  						  }
	  						}

	  					}
	        		  }else{
	        			  // 比例不相同不计算，金额默认为0
	        			  feeGrid.updateRow(rows[i],{
	  		                    feeAmt: 0
	  		                });
	        		  }
        		  }else{
        			  var isFixedAmt = rows[i].isFixedAmt;
        			  var fixedAmt = rows[i].fixedAmt;
        			  if(typeof fixedAmt=='number'&&isFixedAmt==1){
        				  if(rows[i].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_PURCHASE){
        					  fixedAmt = totalRsrvPcStr;
        				  }
        				 if(rows[i].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_62){
                             if(isSplMfr == '1'&&calId){
                                 fixedAmt = rows[i].fixedAmt;
                             }else {
                                 var amt = (parseFloat(fixedAmt * prdNum)).toFixed(2);
                                 fixedAmt = amt;
                             }
        		        	  }
        				  feeGrid.updateRow(rows[i],{
  		                    feeAmt: fixedAmt
  		                });

        			  }

        		  }
        		/*   if(rows[i].fixedAmt){
        		 var amt =(parseFloat(rows[i].fixedAmt)).toFixed(2);
        			  	//是固定值
		  			  	//设置比例信息
		  			  	var feePct = (amt/contAmt*100).toFixed(feeScale);
		  			  		 if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
		  			  				feeGrid.updateRow(rows[i],{
		  			                    feeAmt: amt,
		  			                    feePct:feePct
		  			                });
		  						}
        		  } */

        	  }
          };

			  }
		  }


	}
	function initCalculatePage(flag){
			 var prpsId=$("#prpsId").val();
		 calculateGrid = $("#ligergrid_calculate").ligerGrid({
			 url:'<%=path%>/project/prjquatprps/getPrjQuatPayById.do?id='+prpsId+'&&prjId='+prjId,
	        method: 'get',
		     columns: [
		         { display: '支付时间', name: 'payDt', render:renderDate, minWidth: 60 },
		         { display: '期次', name: 'payPd',minWidth: 140},
		         { display: '租金', name: 'rntAmt', minWidth: 140, type:'currency',render:renderAmt,editor: {type: 'number',
		        	 precision:2,
	    				toFix:true,
	    				onToFix:function(){
    					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
    				}
		         }, enabledSort:true},
		         { display: '本金', name: 'prinAmt', minWidth: 60, type:'currency',
		        	 render:renderAmt},
		         { display: '利息', name: 'intAmt', minWidth: 140, type:'currency',
		        		 render:renderAmt},
		         { display: '剩余本金', name: 'remPrinAmt', minWidth: 140, type:'currency',
		        			 render:renderAmt},
		     ],
		     onBeforeEdit: function (e) {
	                e.lastValue = e.value;
	                if(!e.record.isModify){
	                	e.record.isModify= CommonConstant.C_YN_N;
	                }
	            },
		        onAfterEdit: function (e) {
		            var calBaseCd = e.record.calBaseCd;
		          	if(e.column.name =="rntAmt"){
		          		var value = e.value;
		          	var lastValue = e.lastValue;
		               	 if(value!=lastValue&&lastValue){
		               		 isModify = true;
		               		e.record.isModify= CommonConstant.C_YN_Y;
		               	 }
		          	}
		          },
		     usePager: false,
		     pageSize:10,
		     root:'rows',
		     record:'total',
		     hideLoadButton : true,
		     width: '100%',
		     height:300,
		     heightDiff:-2,
		     //isScroll: false,
		     checkbox:true,
		     enabledEdit: flag,
		     rownumbers:true
		});
	}
	//格式化为人民币格式
	function renderAmt(rowdata, rowindex, value) {
		value = Number(value);
		if(typeof value =='number'){

           var  h="￥" + FormatMoney((parseFloat(value)).toFixed(2));
            return h;
		}
    }
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}

	function setSplitDefValue(){
		//设置拆分比例为0 不可修改
        var form1 = liger.get("formSet1");
		var payWayCd = $("#payWayCd").val();
		if(payWayCd&&(payWayCd==ProjectConstant.CODE_MULTI__STEP_INTER||payWayCd==ProjectConstant.CODE_END_NO_EQUAL||payWayCd==ProjectConstant.CODE_BEGI_NO_EQUAL)){
			var defVal = "0.0";
			form1.setData({
				 quatSplitPct:defVal
	     	 });
			 liger.get("quatSplitPct").setDisabled(true);
		}else{
			if(payWayCd&&(payWayCd==ProjectConstant.CODE_BEGI_EQUAL__PRINC_INTER||payWayCd==ProjectConstant.CODE_END_EQUAL__PRINC_INTER)){
				var splitPct = $("#quatSplitPct").val();
				if(!splitPct||splitPct==0){
					if(defSplitPct){
					   splitPct =defSplitPct;
					}
				}
				 form1.setData({
					 quatSplitPct:splitPct
		     	 });
				 liger.get("quatSplitPct").setDisabled(true);
			}else{
			 liger.get("quatSplitPct").setEnabled(true);
			}
		}
		if(payWayCd&&(payWayCd==ProjectConstant.CODE_END_NO_EQUAL||payWayCd==ProjectConstant.CODE_BEGI_NO_EQUAL)){
			$("#recovery").show();
		}else{
			$("#recovery").hide();
		}
		if(payWayCd==ProjectConstant.CODE_MULTI__STEP_INTER){
			if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_YC||buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZK){
				$("#preRntPct").attr("validate", "{required:true}");
				$("#prjPreRntPctDiv").show();
			}
		}else{
			$("#preRntPct").attr("validate", "");
			$("#prjPreRntPctDiv").hide();
		}
		if(payWayCd==ProjectConstant.CODE_MULTI_STEP_INTER_19){
			$("#speLsPdDiv").show();
		}else{
			$("#speLsPdDiv").hide();
		}

	}
	//恢复到相应的等额本息数据
	function recoveryData(){
		  var form = liger.get("formSet1");
		  var data = form.getData();
		   var detailListData = feeGrid.getData();
		    var id = $("#prpsId").val();
	           data["id"]= id;
	           data["prjId"] = prjId;
	           data["lsPdUntCd"]=$("#lsPdUntCd").val();
	           data["lsCalWayCd"]=$("#lsCalWayCd").val();
	           data["intRateWayCd"]=$("#intRateWayCd").val();
	           data["dpstHdlWayCd"]=$("#dpstHdlWayCd").val();
	           data["expHdlWayCd"]=$("#expHdlWayCd").val();
	           data["noPayWayCd"]=$("#noPayWayCd").val();
	       	   data["feeDetailList"] = JSON.stringify(detailListData);
	       	   data["isModify"] = isModify;
	       	   data["prpsTypCd"]=$("#prpsTypCd").val();
	       	   data["actLsAmt"]=$("#actLsAmt").val();
	       	var payWay = $("#payWayCd").val();
	       	var calculateGridData ;
	     	if(payWay==ProjectConstant.CODE_END_NO_EQUAL){
	     		data["payWayCd"]=ProjectConstant.CODE_END_EQUAL__PRINC_INTER;
	     	}
	      	if(payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
	      		data["payWayCd"]=ProjectConstant.CODE_BEGI_EQUAL__PRINC_INTER;
	     	}

	$.ajax({
		type: 'post',
		dataType:'json',
		data:data,
		url: '<%=path%>/project/prjquatprps/calculate.do',
		success:function(msg){
			 if(msg.success == 1){
				 prjQuatPrps = msg.data;
				 if(prjQuatPrps.isShowIns == CommonConstant.C_YN_Y){
					 $.ligerDialog.SQopen({
						 width: 800,
						 top: 100,
						 buttons: [
							 {
								 text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
									 $.ligerDialog.hide();
								 }
							 }
						 ],
						 title : '机构筛选结果',
						 target: $("#res_div")
					 });
					 isAllowNonIns = prjQuatPrps.isAllowNonIns;
					 if(isAllowNonIns == CommonConstant.C_YN_Y){
						 $("#isAllowNonIns").html("特批标识：是");
					 }else{
						 $("#isAllowNonIns").html("特批标识：否");
					 }
					 if(prjQuatPrps.gctInsResList == null || !(prjQuatPrps.gctInsResList.length>0)){
						 $("#defaultText").show();
						 $("#defaultTip").hide();
					 }else{
						 $("#defaultText").hide();
						 $("#defaultTip").show();
					 }
					 ligerGrid_heguijigou.loadData({rows:prjQuatPrps.gctInsResList});
					 ligerGrid_heguijigouUn.loadData({rows:prjQuatPrps.ungctInsResList});
				 }else{
					 calculateData =  msg.data.prjQuatPrpsPaySchPage;
					 $("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
					 $("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
					 $("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
					 $("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
					 $("#actLsAmt").val(prjQuatPrps.actLsAmt);
					 $("#irrPct").val(prjQuatPrps.irrPct);
					 $("#irrPct2").val(null==prjQuatPrps.irrPct2?"":prjQuatPrps.irrPct2);
					 $("#tenThouCoef").val(null==prjQuatPrps.tenThouCoef?"":prjQuatPrps.tenThouCoef);
					 $("#eachEstRntAmt").val(prjQuatPrps.eachEstRntAmt);
					 if(!prjQuatPrps.checkResultDesc&&insCode){
						 $("#insMsgDiv").show();
						 $("#checkInfo").text("该方案无合适的机构！");
					 }
					 if(prjQuatPrps.checkResultDesc&&insCode){
						 $("#insMsgDiv").show();
						 $("#checkInfo").text(prjQuatPrps.checkResultDesc);
					 }
					 calculateGrid = $("#ligergrid_calculate").ligerGrid({
						 data: $.extend(true,{},calculateData),
						 columns: [
							 { display: '支付时间', name: 'payDt', render:renderDate, minWidth: 60 },
							 { display: '期次', name: 'payPd',minWidth: 140},
							 { display: '租金', name: 'rntAmt', minWidth: 140, type:'currency',render:renderAmt,
								 editor: {type: 'number',
									 precision:2,
									 toFix:true,
									 onToFix:function(){
										 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
									 }},
								 enabledSort:true},
							 { display: '本金', name: 'prinAmt', minWidth: 60, type:'currency',
								 render:renderAmt},
							 { display: '利息', name: 'intAmt', minWidth: 140, type:'currency',
								 render:renderAmt},
							 { display: '剩余本金', name: 'remPrinAmt', minWidth: 140, type:'currency',
								 render:renderAmt},
						 ],
						 onBeforeEdit: function (e) {
							 e.lastValue = e.value;
							 if(!e.record.isModify){
								 e.record.isModify= CommonConstant.C_YN_N;
							 }
						 },
						 onAfterEdit: function (e) {
							 var calBaseCd = e.record.calBaseCd;
							 if(e.column.name =="rntAmt"){
								 var value = e.value;
								 var lastValue = e.lastValue;
								 if(value!=lastValue&&lastValue){
									 isModify = true;
									 e.record.isModify= CommonConstant.C_YN_Y;
								 }
							 }

						 },
						 usePager: false,
						 pageSize:10,
						 root:'rows',
						 record:'total',
						 hideLoadButton : true,
						 width: '100%',
						 height:300,
						 heightDiff:-2,
						 //isScroll: false,
						 checkbox:true,
						 enabledEdit: true,
						 rownumbers:true
					 });
				 }
			 }else{
				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			 }
		}
	});

	}

	function showBusinessIns(){
		var ligerForm = liger.get("formSet1");
		var isBp = $("#isBp").val();
		if(isBp=="1"&&prjTypCd==ProjectConstant.PRJ_TYP_CD_CPYW){
			 var ligerForm = liger.get("formSet1");
		     ligerForm.setFieldValidate("businessInsCd", {
                 required: true,
                 select: true
             });
		    //$("#businessInsCd").attr("validate", "{required:true}");
			$("#businessInsCdDiv").show();
			$("#businessInsCdReq").show();
		}else{
			if(isBp&&isBp=="0"){
			   ligerForm.setFieldValidate("businessInsCd", {
	                 required: true,
	                 select: false
	             });
			}
		    //$("#businessInsCd").attr("validate", "");
			$("#businessInsCd").val(" ");
			$("#businessInsCdDiv").hide();
			$("#businessInsCdReq").hide();
		}
	}
	/**
	 * 此机构是否可修改包牌的费用项
	 * 目前浦发和江西金租 、xwbank、xycbank、shnsbank、pabank
     * 包牌项任意都可修改购置税和保险
	 * @param insCode
	 * @returns {boolean}
	 */
	function isBpCanWtsIns(insCode){
		if(!insCode||(insCode!=ProjectConstant.PRJ_INS_CODE_PF
				&&insCode!=ProjectConstant.PRJ_INS_CODE_JXFL
				&&insCode!=ProjectConstant.PRJ_INS_CODE_XWBANK
				&&insCode!=ProjectConstant.PRJ_INS_CODE_XYCBANK
                &&insCode!=ProjectConstant.PRJ_INS_CODE_SHNSBANK
				&&insCode!=ProjectConstant.PRJ_INS_CODE_PABANK)){
			return true ;
		}else{
			return false ;
		}
	}
</script>



</body>
</html>
